-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCake.java
More file actions
36 lines (26 loc) · 906 Bytes
/
Copy pathCake.java
File metadata and controls
36 lines (26 loc) · 906 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
32
33
34
35
36
package WhileLoop;
import java.util.Scanner;
public class Cake {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int width = Integer.parseInt(scanner.nextLine());
int length = Integer.parseInt(scanner.nextLine());
int cakePieces = width * length;
boolean noMoreLeft = false;
String input = scanner.nextLine();
while(!input.equals("STOP")){
int pieces = Integer.parseInt(input);
cakePieces -= pieces;
if(cakePieces <= 0){
noMoreLeft = true;
break;
}
input = scanner.nextLine();
}
if(noMoreLeft){
System.out.printf("No more cake left! You need %d pieces more.",Math.abs(cakePieces));
}else {
System.out.printf("%d pieces are left.",cakePieces);
}
}
}