Home »
Java Programs »
Java Basic Programs
Java program to read the height of the person, and the print person is taller, dwarf, or average height person
Given the height of a person, we have to read the height of the person, and the print person is taller, dwarf, or average height person.
Submitted by Nidhi, on March 01, 2022
Problem statement
In this program, we will read the height of the person in centimetres and print the message based on input height.
Source Code
The source code to print person is taller, dwarf, or average height person is given below. The given program is compiled and executed successfully.
// Java program to read the height of the person,
// and the print person is taller, dwarf,
// or average height person
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner SC = new Scanner(System.in);
double height = 0;
System.out.printf("Enter Height (in centimeters): ");
height = SC.nextDouble();
if ((height >= 150.0) && (height <= 170.0))
System.out.printf("Person is average height person");
else if ((height > 170.0) && (height <= 195.0))
System.out.printf("Person is taller");
else if (height < 150.0)
System.out.printf("Person is dwarf");
else
System.out.printf("Abnormal height \n");
}
}
Output
Enter Height (in centimeters): 174.34
Person is taller
Explanation
In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contains a static method main().
The main() method is an entry point for the program. Here, we read the height of the person in centimeters from the user using the Scanner class. Then we printed the appropriate message.
Java Basic Programs »