java - why does the for-loop go through the args three times? -
i want know why for-loop counts through args 3 times , doesn't stop after first loop? code :
public class test2 { public static void main(string[] args) { int n = args.length; int[] x = new int[n]; int count = 0; (int = 0; < x.length; i++) { x[i] = integer.parseint(args[i]); } (int = 0; < n; i++) { (int j = i+1; j < n; j++) { if (x[j] != x[j-1]) { count++; } system.out.println(count); } } system.out.println(n-count); }
}
i think mean this:
(int j = 1; j < n; j++) { if (x[j] != x[j-1]) { count++; } system.out.println(count); } system.out.println(n-count);
instead of:
for (int = 0; < n; i++) { (int j = i+1; j < n; j++) { if (x[j] != x[j-1]) { count++; } system.out.println(count); } } system.out.println(n-count);
Comments
Post a Comment