Write a program in Java that asks the name of the user. The program will prompt
ID: 3665571 • Letter: W
Question
Write a program in Java that asks the name of the user. The program will prompt "What is your name?" the user types his/her name.
The program should then ask for height and weight of the user.
It should then print on separate lines, "Name of the User" your height in metric system is (prints out the height in Meters and cm. For example, your height in metric system is 1 meter 45 cm.
It should then print the weight in KG and grams (same as above your weight in metric system is ----)
The program should end by the statement "Good Bye. Go _____ beat _____."
Explanation / Answer
Answer -
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scanner = new Scanner( System.in );
System.out.println("What is your name : ");
String name = scanner.nextLine();
System.out.println("What is your height in inches : ");
int height = scanner.nextInt();
System.out.println("What is your weight in Pounds : ");
int weight = scanner.nextInt();
int hm=0,hcm;
hm=((height*254)/100)/100;
hcm=((height*254)/100)%100;
int wkg=0,wgm;
wkg=((weight*4535)/100)/100;
wgm=((weight*4535)/100)%100;
System.out.println("your name : "+name);
System.out.println("your height : "+hm+" Meters "+hcm+" Centimeters");
System.out.println("your weight : "+wkg+" Kilogram "+wgm*10+" Grams");
System.out.println("Good Bye. Go _____ beat _____.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.