1 Reply Latest reply: Jul 6, 2007 4:30 PM by 807605 RSS

    Trouble with Parsing String

    807605
      I am trying to take a string input from the command line and push it to an array then compare the array to another to see if there are any identical values. Here is the code in case it doesn't make sense.
      //
      //  Parser.java
      //  PLCProject1
      //
      //  Created by MilesB.
      //  Copyright 2007 . All rights reserved.
      //
      import java.io.*;
      import java.util.*;
      import java.lang.*;
      
      public class Parser {
      
      public static void main(String[] args)
           {
           
                //Prompt the user to enter in String.
                System.out.println("Please enter in String to be tested");
                Scanner MyScan = new Scanner(System.in);
                
                String StringToTest = MyScan.next();
                
                char StringTestArray[] = new char[StringToTest.length()];
                int Array[] = {1,2, 3, 4, 5, 6, 7, 8, 9, 0};
                
                for(int j=0; j< StringToTest.length()-1; j++)
                     {
                          System.out.println(StringToTest + " ");
                          System.out.print(Array[j]);
                     }
                
                //open up standard input from CLI
                //BufferedReader ReadIn = new BufferedReader (new InputStreamReader(System.in));
           
                //StringToTest = ReadIn;
                
                //Testing the Entered String to see if it contains numeric values.
                for(int i=0; i< StringToTest.length()-1; i++)
                {
                     for(int k=0; k< StringToTest.length()-1; k++)
                     if (StringTestArray[i] == Array[k])
                          {
                               System.out.println("This String contains numeric values");
                               break;
                          }
                     else
                     System.out.println("This Char is good");
                }
                
                     System.out.println("This String was good");
      
           }
      
      }