Solution:: Exercise Sheet: Java If Statement

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

MIS 202 – Introduction to Programming Exercise Sheet: Java Operators

EXERCISE SHEET: JAVA IF STATEMENT


Ex 1. Write a Java program that reads a value from user and check if it is odd or even. Display
the output on screen.
Solution:

Ex 2. Write a Java program that reads two values from user and check if either of them is
divisible by the other, then print the result on screen.
Examples of running:
If the user entered 15 and 5, the output should be: Yes, 15 is divisible by 5.
If the user entered 3 and 12, the output should be: Yes, 12 is divisible by 3.
If the user entered 7 and 13, the output should be: None is divisible.
Solution:

Ex 3. Write a Java program that reads 2 integers from the user and prints the greater value.
Solution:

Ex 4. Write the Java program that asks the user to enter the car speed, the program reads the
speed and check:
if the Speed is from 0 to 60, the program will print: “No ticket”
if the Speed is from 61 to 80, the program will print: “Small ticket”
if the Speed is more than 80, the program will print: “Big ticket”
Solution:

You might also like