You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Declare a double variable weightKgs and take input from the user in kilograms. Also, Create a method convert(double kgs) and convert the weight to grams and milligrams.
importjava.util.Scanner;
publicclassWeightConverter {
publicstaticvoidmain(Stringargs[]) {
Scannersc = newScanner(System.in);
System.out.println("Enter the weight in kilograms ");
doubleweightKgs = sc.nextDouble();
convert(weightKgs);
}
publicstaticvoidconvert(doubleKgs) {
doubleweightGms, weightMg;
weightGms = Kgs * 1000;
weightMg = weightGms * 1000;
System.out.println("The converted weight in grams is = " + weightGms);
System.out.println("The converted weight in miligrams is = " + weightMg);