You seem to be confused about whether you actually want an array or not. You're parsing a single value, but trying to assign that int
to c
which is an array variable. You don't really need one, as you only need to remember the current maximum, and the value you've just parsed:
int max = Integer.MIN_VALUE;
while (strTok.hasMoreTokens()) {
int value = Integer.parseInt(strTok.nextToken());
if (value > max) {
max = value;
}
}
If you really want an array, then you'll need to know how many tokens there are before you parse them, which is tricky.
Another alternative would be to create a List<Integer>
:
// First parse everything...
List<Integer> values = new ArrayList<>();
while (strTok.hasMoreTokens()) {
values.add(Integer.parse(strTok.nextToken());
}
// Then you can find the maximum value in the list
Personally I prefer the first approach, if you only need to find the maximum value.