0% found this document useful (0 votes)
84 views1 page

Solution:: Exercise Sheet: Java If Statement

This document contains 4 exercises for a Java programming assignment on if statements. The exercises involve: 1) Checking if a user-input value is odd or even. 2) Checking if user-input values are divisible by each other and printing the results. 3) Printing the greater of two user-input integers. 4) Checking a user-input car speed, printing the type of ticket ("No ticket", "Small ticket", "Big ticket") based on predefined speed ranges. Sample solutions are provided for each exercise.

Uploaded by

ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views1 page

Solution:: Exercise Sheet: Java If Statement

This document contains 4 exercises for a Java programming assignment on if statements. The exercises involve: 1) Checking if a user-input value is odd or even. 2) Checking if user-input values are divisible by each other and printing the results. 3) Printing the greater of two user-input integers. 4) Checking a user-input car speed, printing the type of ticket ("No ticket", "Small ticket", "Big ticket") based on predefined speed ranges. Sample solutions are provided for each exercise.

Uploaded by

ibrahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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