0

How to stop this loop?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner a = new Scanner(System.in); int x=a.nextInt(); int y=a.nextInt(); int n=x+y; while (n < 42) { System.out.println("ok"); y=y+10; } } } //never ending loop, how to make it stop at some point?

4th Feb 2017, 10:14 PM
Jon Selaya
Jon Selaya - avatar
3 Antworten
+ 4
add something to n inside the loop
4th Feb 2017, 10:17 PM
jay
jay - avatar
+ 3
you should be checking value for n not y so change it to n=n+10;
4th Feb 2017, 10:21 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
It worked, tysm!
4th Feb 2017, 10:23 PM
Jon Selaya
Jon Selaya - avatar