java - Why does if statement not work properly inside for loop? -
i have array classified same value..
int[] clusters= 0 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 int[] clusterdistinct = 0 1 2
it fine using code below, on last statement (if statement) inside loop not print. don't know whats wrong code
private void autoclustering(int[] clusters) { int[] clusterdistinct = getclusters(clusters); (int = 0; < clusterdistinct.length; i++) { system.out.println("\ncluster " + clusterdistinct[i]); (int j = 0; j < clusters.length; j++) { if (clusters[j] == clusterdistinct[i]){ system.out.print(j+","); } } } } private int[] getclusters(int[] clusters) { arraylist<integer> klaster = new arraylist<integer>(); (int = 0; < clusters.length; i++) { boolean isdistinct = false; (int j = 0; j < i; j++) { if (clusters[i] == clusters[j]) { isdistinct = true; break; } } if (!isdistinct) { klaster.add(clusters[i]); } } int[] clusterdistinct = new int[klaster.size()]; (int = 0; < clusterdistinct.length; i++) clusterdistinct[i] = klaster.get(i).intvalue(); return clusterdistinct; }
here output.. if statement not working (not print) on last cluster. cluster 2 (last statement) not print, should print 2,25
why not print anything?
06-10 20:38:34.204: i/system.out(10634): cluster 0: 06-10 20:38:34.204: i/system.out(10634): 0, 06-10 20:38:34.204: i/system.out(10634): cluster 1: 06-10 20:38:34.204: i/system.out(10634): 1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50, 06-10 20:38:34.204: i/system.out(10634): cluster 2: 06-10 20:38:34.204: d/brcm_egl(10634): eglmakecurrent(null) thread: 10634 06-10 20:38:34.204: d/brcm_egl(10634): egldestroysurface() surface: 0x4d4beb30, android window 0x4d4be420, thread: 10634
print newline character \n
after loop flush output buffer.
Comments
Post a Comment