-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabTest2.java
More file actions
41 lines (39 loc) · 1.29 KB
/
LabTest2.java
File metadata and controls
41 lines (39 loc) · 1.29 KB
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
37
38
39
40
41
import java.util.Scanner;
public class LabTest2 {
public static void main(String[] args) {
double centimeter;
Scanner sc = new Scanner(System.in);
try{
System.out.print("Please enter feet: ");
String ifeet = sc.nextLine();
double feet = Double.parseDouble(ifeet);
if(feet>=0.00){}
else
{
throw new NumberFormatException();
}
System.out.print("Please enter inch: ");
String iinch = sc.nextLine();
double inches = Double.parseDouble(iinch);
if(inches>=0.00){}
else
{
throw new NumberFormatException();
}
if(feet >= 0 && inches >=0){
centimeter = feet * 30.48 + inches * 2.54;
System.out.println("The total centimeter is " + centimeter);
}else{
throw new IllegalArgumentException();
}
}
catch(NumberFormatException ex){
System.out.println("The input must be digit.");
System.out.println("Please re-enter input.");
}
catch(IllegalArgumentException e){
System.out.println("The input must be positive number.");
System.out.println("Please re-enter input.");
}
}
}