R
R
I am reading data from a file, each line has a certain number of
integers. They are seperated by whitespace. When I read them in I use the
readLine() method which reads the lines in as a string. What I am trying to
do is seperate each of these integers so that I can compare them to other
integers on other lines. How do I seperate the integers seeing that they are
all in a single string? This is the code I have tried to use but havent had
any luck as of yet:
String maxVals = in.readLine();
maxVals = maxVals.trim();
System.out.println("Max values are: " + maxVals);
int i = 0;
char buff = maxVals.charAt(i);
System.out.println("buff is: " + buff);
i++;
while (buff.compareTo(' ') > 0){
buff += maxVals.charAt(i);
i++;}
I get an error saying that char cannot be dereferenced. I am not even
sure if this way will work because some of the integers are more than on
digit. When I add them together I won't get a 10 instead I will get 'a'. How
do I extract integers that are more than 1 digit?
Thanks
EF
integers. They are seperated by whitespace. When I read them in I use the
readLine() method which reads the lines in as a string. What I am trying to
do is seperate each of these integers so that I can compare them to other
integers on other lines. How do I seperate the integers seeing that they are
all in a single string? This is the code I have tried to use but havent had
any luck as of yet:
String maxVals = in.readLine();
maxVals = maxVals.trim();
System.out.println("Max values are: " + maxVals);
int i = 0;
char buff = maxVals.charAt(i);
System.out.println("buff is: " + buff);
i++;
while (buff.compareTo(' ') > 0){
buff += maxVals.charAt(i);
i++;}
I get an error saying that char cannot be dereferenced. I am not even
sure if this way will work because some of the integers are more than on
digit. When I add them together I won't get a 10 instead I will get 'a'. How
do I extract integers that are more than 1 digit?
Thanks
EF