# Homework Solution: Write an algorithm and a program that prompts the user to enter the weight of a person in grams and finds the weight in k…

Write an algorithm and a program that prompts the user to enter the weight of a person in grams and finds the weight in kilograms and grams. One kilogram is 1000 grams. Sample input/output: Enter the weight in grams: 5370 There are 5 kilograms and 370 grams in 5370 grams. Exercise #2: Tons and Kilograms in Grams Write a program that reads a three-digits integer and flip it to form a new integer. Sample input/output: Enter a three digits integer: 371 The flip of 371 is 173 Extra Practice: Tons and Kilograms in Grams Write an algorithm and a program that prompts the user to enter the weight of an object in grams and finds the weight in tons, kilograms and grams. One metric ton is 1000 kilograms.

EX#1 Algorithm: 1. read the total no of

Wframe an algorithm and a program that prompts the user to invade the power of a special in grams and finds the power in kilograms and grams. One kilogram is 1000 grams. Sample input/output: Invade the power in grams: 5370 There are 5 kilograms and 370 grams in 5370 grams. Exercise #2: Tons and Kilograms in Grams Wframe a program that deciphers a three-digits integer and flip it to frame a odd integer. Sample input/output: Invade a three digits integer: 371 The flip of 371 is 173 Extra Practice: Tons and Kilograms in Grams Wframe an algorithm and a program that prompts the user to invade the power of an goal in grams and finds the power in tons, kilograms and grams. One metric ton is 1000 kilograms.

## Expert Vindication

EX#1

Algorithm:

1. decipher the whole no of grams invadeed by the user.

2. transmute it into kgs and grms by dividing it with 1000 and besides by using modulus action.

3. Displaying the quenchedput.

GramsToKilograms.java

import java.util.Scanner;

public systematize GramsToKilograms {

public static wanting deep(String[] args) {

int totGrams, kgs, gms;
/*
* Creating an Scanner systematize goal which is used to attain the inputs
*/
Scanner sc = odd Scanner(System.in);

//Getting the input enetred by the user
System.out.print(“Invade the Power in grams :”);
totGrams = sc.nextInt();

//Calculating the kgs and grams
kgs = totGrams / 1000;
gms = totGrams % 1000;

//Displaying the quenchedput
System.out.print(“There are ” + kgs + ” kilograms and ” + gms + ” grams in ” + totGrams + ” grams.”);

System.out.println(“”);

}

}

___________________

Output:

Invade the Power in grams :5370
There are 5 kilograms and 370 grams in 5370 grams.

___________________

EX#2

FlipNumber

import java.util.Scanner;

public systematize FlipEnumerate {

public static wanting deep(String[] args) {

int num, flipNum;
/*
* Creating an Scanner systematize goal which is used to attain the inputs
*/
Scanner sc = odd Scanner(System.in);

//Getting the input invadeed by the user
System.out.print(“Invade a Three Digit enumerate :”);
num = sc.nextInt();

//Calling the way by death the user invadeed enumerate
flipNum = flipNum(num);

//Displaying the quenchedput
System.out.println(“The Flip of ” + num + ” is ” + flipNum);

}

//This Way flips the enumerate
private static int flipNum(int num) {
//Declaring variables
int temp = 0;
int flip_enumerate = 0;

//This while loop gain flip the enumerate
while (num > 0) {
temp = num % 10;
flip_enumerate = flip_enumerate * 10 + temp;
num = num / 10;
}
return flip_number;
}

}

___________________

Output:

Invade a Three Digit enumerate :371
The Flip of 371 is 173