0
why does this code create an infinite loop
public int[] Returned(int t){ Scanner N = new Scanner(System.in); Scanner H = new Scanner(System.in); int[] answer = new int[t]; for (int i=0;i<=t;i++){ int n=N.nextInt(); int[] Hi = new int[n]; for (int ii=0;ii<n;ii++){ Hi [ii] = H.nextInt(); } int omega=0; int total=0; while (omega<n){ omega++; if (Hi[omega]>Hi[omega--]&&Hi[omega]>Hi[omega++]){ total++; } } answer[i]=total; } return answer; }
1 ответ
+ 3
Make this code in Sololearn Code Playground and share the link.
You can use single scanner to get multiple input. Don't take single input inside loop.