Programming Assignment III
Programming Assignment III
(Conditional Statements)
1. Write a java program to input the height of the person and check if the height of the person is
greater than or equal to 6 feet then print the message “The person is tall”.
2. Write a java program to input the mark of a student and check if the student mark is greater than
or equal to 40, then it generates the following message.
”Congratulation! You have passed the exam.”
Otherwise the output message is ”Sorry! You have failed the exam.”
3. Input an integer through the keyboard. Write a java program to find whether it is an odd number
or even number.
4. Write a java program that takes three integers as command-line arguments and prints equal if all
three are equal, and not equal otherwise.
5. Write a java program that prints true if the double variables x and y are both strictly between 0
and 1 and false otherwise.
6. Write a java program to determine whether the character entered is a capital letter, a small case
letter, a digit or a special symbol. The following table shows the range of ASCII values for various
characters.
Characters ASCII Values
A – Z 65 – 90
a – z 97 – 122
0 – 9 48 – 57
special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127
7. Given three points (x1, y1), (x2, y2) and (x3, y3), write a java program to check if all the three
points fall on one straight line.
Hint: Three points are collinear, if slope of one set of points = slope of other set of points.
8. If the ages of Rahul, Ayush and Ajay are input through the keyboard, write a java program to
determine the youngest of the three.
Page 1 of 5
9. Write a java program that takes the x – y coordinates of a point in the Cartesian plane and prints
a message telling either an axis on which the point lies or the quadrant in which it is found.
Sample lines of output:
(-1.0, -2.5) is in quadrant III
(0.0, 4.8) is on the y-axis
10. Write a java program that prints the roots of the polynomial ax 2 + bx + c, prints an appropriate
message if the discriminant is negative, and behaves appropriately (avoiding division by zero) if a
is zero.
11. The body mass index (BMI) is commonly used by health and nutrition professionals to
estimate human body fat in populations. It is computed by taking the individual's weight (mass) in
kilograms and dividing it by the square of their height in meters.
i.e. BMI =weight(kg) / (height(m))2
Then use some if statements to show the category for a given BMI.
BMI Category
12. Write a java program which inputs one positive integer specifying the year of birth of a person
and returns an output the name of the generation that the person is part of (’X’, ’Y’,or ’Z ’)
according to the table below. For births before 1966, return ’O’ for Old and for births after 2012,
return ’K’ for Kid.
Generation Born
Page 2 of 5
X 1966-1980
Y 1981-1999
Z 2000-2012
13. An University conducts a 100 mark exam for its student and grades them as follows. Assigns a
grade based on the value of the marks. Write a java program to print the grade according to the
mark secured by the student. [Use switch-case]
>=90 O
<40 F
14. Write a java program that reads the lengths of the three sides of a triangle and determines the
type of the triangle according to the following pseudo code.
15. Make a java program which displays an appropriate name for a person, using a combination of
nested ifs and compound conditions. Ask the user for a gender, first name, last name and age. If
the person is female and 20 or over, ask if she is married. If so, display "Mrs." in front of her
name. If not, display "Ms." in front of her name. If the female is under 20, display her first and last
name. If the person is male and 20 or over, display "Mr." in front of his name. Otherwise, display
his first and last name. Note that asking a person if they are married should only be done if they
are female and 20 or older, which means you will have a single if and else nested inside one of
your if statements. Also, did you know that with an if statements (or else), the curly braces are
optional when there is only one statement inside?
What is your gender (M or F): F
First name: Gita
Last name: Pattanayak
Age: 32
Are you married, Gita (y or n)? y
Then I shall call you Mrs. Gita Pattanayak.
What is your gender (M or F): F
First name: Anjali
Last name: Mishra
Age: 48
Are you married, Anjali(y or n)? n
Then I shall call you Ms. Anjali.
What is your gender (M or F): M
First name: Ashok
Last name: Mohanty
Age: 23
Then I shall call you Mr. Ashok.
Page 4 of 5
What is your gender (M or F): M
First name: Rahul
Last name: Pati
Age: 15
Then I shall call you Rahul Pati.
Page 5 of 5