forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroDestiny.java
More file actions
31 lines (27 loc) · 757 Bytes
/
ZeroDestiny.java
File metadata and controls
31 lines (27 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class ZeroDestiny
{
public static int youMustEnterZero(int num)
{
int count = 0;
Scanner in = new Scanner(System.in);
while (num != 0)
{
System.out.println("Try Again: ");
num = in.nextInt();
count++;
}
System.out.println("You entered Zero!");
return count;
}
public static void main(String[] args)
{
int number;
int counter;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number: ");
number = scanner.nextInt();
counter = youMustEnterZero(number);
System.out.println("You entered a number other than zero: " + counter);
}
}