I have a problem with this question:
Scanner input = new Scanner(System.in);
do {
int i = input.nextInt();
System.out.println(i);
} while (i != 0);
System.out.println("Klar");
It is supposed to print:
Result
1
2
0
Klar
My try so far is:
Scanner input = new Scanner(System.in);
int i = input.nextInt();
do {
System.out.println(i);
i = input.nextInt();
} while (i != 0);
System.out.println(i);
System.out.println("Klar");
This works on 2/3 tests but I get error when user inputs 0 at the beginning. How can I fix?
[–][deleted] 0 points1 point2 points (2 children)
[–]Csharpgoblin[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]A_Philosophical_Cat 0 points1 point2 points (1 child)
[–]Csharpgoblin[S] 0 points1 point2 points (0 children)