Q:

Java program to read the height of the person, and the print person is taller, dwarf, or average height person

belongs to collection: Java Basic Programs

0

Java program to read the height of the person, and the print person is taller, dwarf, or average height person

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read the height of the person in centimetres and print the message based on input height.

Program/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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find the sum of two numbers using ... >>
<< Java program to extract the last two digits from a...