why does this code create an infinite loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

22nd Apr 2020, 8:56 AM
Sheldon Mark
Sheldon Mark - avatar
1 Answer
+ 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.
22nd Apr 2020, 11:12 AM
A͢J
A͢J - avatar