-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatyears.java
More file actions
31 lines (24 loc) · 910 Bytes
/
catyears.java
File metadata and controls
31 lines (24 loc) · 910 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 CatAgeCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What is your cat's name?");
String catName = scanner.nextLine();
System.out.println("What is your cat's age?");
String catAgeInput = scanner.nextLine();
int catAge = 0;
try {
catAge = Integer.parseInt(catAgeInput);
} catch (NumberFormatException e) {
catAge = 0;
}
if (catAge < 2) {
System.out.println("Please set your cat to be more than 2.");
}
int earlyYears = 24;
int laterYears = (catAge - 2) * 4;
int humanYears = earlyYears + laterYears;
System.out.println("Your cat " + catName + " is " + humanYears + " years old.");
scanner.close();
}
}