The following example takes a sum Integers as program arguments and calculates the average out of them. But somehow it prints "NaN"
public static void main(String args[]) {
int sum= 0;
for(int i= 0; i < args.length; i++) {
sum= sum + Integer.parseInt(args[i]);
}
System.out.println("Average: " + (float)sum / args.length);
}
How it could evaluate to NaN
?
args
is empty. Your code assumes otherwise. When you step through this in a debugger, what happens?