-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightConverter.java
More file actions
41 lines (29 loc) · 1.04 KB
/
WeightConverter.java
File metadata and controls
41 lines (29 loc) · 1.04 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 WeightConverter {
public static void main(String[] args) {
// Weight Conversion program
Scanner scanner = new Scanner(System.in);
int choice;
double weight;
double newWeight;
System.out.println("Weight Conversion Program");
System.out.println("1: Convert lbs to kgs");
System.out.println("2: Convert kgs to lbs");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
if(choice == 1) {
System.out.print("Enter the weight in lbs: ");
weight=scanner.nextDouble();
newWeight=weight*0.453592;
System.out.printf("The weight in kgs is %.2f", newWeight);
} else if(choice == 2) {
System.out.print("Enter the weight in kgs: ");
weight=scanner.nextDouble();
newWeight=weight*2.20462;
System.out.printf("The weight in kgs is %.2f", newWeight);
} else {
System.out.println("Please choose either 1 or 2!");
}
scanner.close();
}
}