Java Program to Categorize Taller, Dwarf and Average by Height of a Person
Last Updated :
20 Nov, 2020
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
class Height_classifier {
public static void main(String[] args)
{
int height = 180 ;
if (height > 175 ) {
System.out.println( "This person is Taller" );
}
else if (height > 150 && height <= 175 ) {
System.out.println(
" This person has Average height" );
}
else {
System.out.println( " This person is Dwarf" );
}
}
}
|
Output
This person is Taller
Implementation using Command line arguments:
Java
class Height_classifier {
public static void main(String[] args)
{
System.out.println(
"Enter the height in centimeters:" );
int height = Integer.parseInt(args[ 0 ]);
if (height > 175 ) {
System.out.println( "This person is Taller" );
}
else if (height > 150 && height <= 175 ) {
System.out.println(
" This person has Average height" );
}
else {
System.out.println( " This person is Dwarf" );
}
}
}
|
Output:
Share your thoughts in the comments
Please Login to comment...