-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightConverter.Java
More file actions
25 lines (25 loc) · 868 Bytes
/
WeightConverter.Java
File metadata and controls
25 lines (25 loc) · 868 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
import java.util.Scanner;
public class WeightConverter
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Are you trying to convert gram or kilo?: ");
String conv = in.next();
if (conv.contains("grams") || conv.contains("gram"))
{
System.out.print("Enter the number of gram: ");
int num = in.nextInt();
Double num2 = new Double(num);
Double kilo = num2 / 1000.0;
System.out.println(num + " grams converted to kilo is " + kilo);
}
else
{
System.out.print("Enter the number of kilo: ");
int num = in.nextInt();
int grams = num * 1000;
System.out.println(num + " kilo converted to grams is " + grams);
}
}
}