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

4 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7446 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS