Saturday, November 16, 2024
Google search engine
HomeLanguagesJavaJava Program to Categorize Taller, Dwarf and Average by Height of a...

Java Program to Categorize Taller, Dwarf and Average by Height of a Person

In this program, categorize taller, dwarf, and average by the height of a person. For comparison, a standard height of reference is taken into consideration as 151cm to 175cm. Height ranging from the limit of 151cm to 175cm comes under average height. Height greater than 175cm comes under the taller height category and height below 150cm comes under the Dwarf category.

Example:

Input:    164
Output: This person has Average height
 
Input:    180
Output: This person is taller

Implementation:

Java




// Java Program to Categorize Taller,
// Dwarf and Average by Height of a Person
  
class Height_classifier {
    public static void main(String[] args)
    {
        int height = 180;
  
        if (height > 175) {
            // prints that person is taller
            System.out.println("This person is Taller");
        }
        else if (height > 150 && height <= 175) {
            // prints that person has average height
            System.out.println(
                " This person has Average height");
        }
        else {
            // prints that person is a graph
            System.out.println(" This person is Dwarf");
        }
    }
}


Output

This person is Taller

Implementation using Command line arguments:

Java




// Java Program to Categorize Taller,
// Dwarf and Average by Height of a Person
  
class Height_classifier {
    public static void main(String[] args)
    {
        System.out.println(
            "Enter the height in centimeters:");
        // taking input from user using command line
        int height = Integer.parseInt(args[0]);
        if (height > 175) {
            // prints that person is taller
            System.out.println("This person is Taller");
        }
        else if (height > 150 && height <= 175) {
            // prints that person has average height
            System.out.println(
                " This person has Average height");
        }
        else {
            // prints that person is a graph
            System.out.println(" This person is Dwarf");
        }
    }
}


Output:

RELATED ARTICLES

Most Popular

Recent Comments