-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightConversion.java
More file actions
42 lines (29 loc) · 1.07 KB
/
WeightConversion.java
File metadata and controls
42 lines (29 loc) · 1.07 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
42
import java.util.Scanner;
public class WeightConversion {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
double weight,newWeight;
int choice;
char kgs,lbs;
System.out.println("1. Convert lbs to kgs");
System.out.println("2. Convert kgs to lbs");
System.out.print("\nEnter your choice : ");
choice = scanner.nextInt();
if(choice==1){
System.out.print("\nEnter the weight (lbs) : ");
weight = scanner.nextDouble();
newWeight = weight * 0.453592;
System.out.printf("%f lbs = %.2f kgs",weight,newWeight);
}
else if(choice==2) {
System.out.print("\nEnter the weight (kg) : ");
weight = scanner.nextDouble();
newWeight = weight / 0.453592;
System.out.printf("%f kgs = %.2f lbs", weight, newWeight);
}
else {
System.out.println("\nInvalid Choice!");
}
scanner.close();
}
}