So I'm trying to find a min and max of an array which are put in by the user.
This is my code
public static void main(String[] args) {
int[] a = new int[args.length];
for (int i = 0; i < args.length; i++) {
a[i] = Integer.parseInt(args[i]);
int max = a[0];
for (int j = 1; j < args.length; j++) {
if (a[j] > max) {
max = a[j];
}
}
System.out.println("the maximum value of the array is " + max);
}
}
But the output I am getting is every single number I have put in. What is my mistake here?
See Question&Answers more detail:os