-
Notifications
You must be signed in to change notification settings - Fork 0
/
DivideLoop.java
24 lines (22 loc) · 927 Bytes
/
DivideLoop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class DivideLoop {
public static void main(String[] args) throws Exception{
divideInts();
}
public static void divideInts() throws Exception{
Scanner systemInScanner = new Scanner(System.in);
System.out.printf("enter an integer\n");
int dividend = systemInScanner.nextInt();
System.out.printf("What integer would you like to divide %d by?\n", dividend);
int divisor = systemInScanner.nextInt();
while(divisor != 0){
int quotient = dividend/divisor;
System.out.printf("%d / %d = %d\n", dividend, divisor, quotient);
System.out.printf("enter an integer\n");
dividend = systemInScanner.nextInt();
System.out.printf("What integer would you like to divide %d by?\n", dividend);
divisor = systemInScanner.nextInt();
}
System.out.printf("Oops. There’s a problem. You can't divide by zero.\n");
}
}