Exercise 2 - Operators Control Statements
Exercise 2 - Operators Control Statements
1. Write a Java program that reads a floating-point number and prints "zero" if the number
is zero. Otherwise, print "positive" or "negative". Add "small" if the absolute value of
the number is less than 1, or "large" if it exceeds 1,000,000. (2)
Test cases:
2. Write a Java program that reads in two floating-point numbers and tests whether they
are the same for three decimal places (2)
3. Write a program to get 5 inputs from user and find the sum and average (1)
4. Write a Java program that accepts three numbers and prints "All numbers are equal" if
all three numbers are equal, "All numbers are different" if all three numbers are
different and "Neither all are equal or different" otherwise (1)
5. Write a Java program that keeps a number from the user and generates an integer
between 1 and 7 and displays the name of the weekday (1)
int i = 10;
int n = i++%5;
if (aNumber >= 0)
if(aNumber == 0)
System.out.println(“First String”);
else System.out.println(“Second String”);
System.out.println(“Third String”);
8. Write a program to calculate the sum of the first and the second last digit of 5 digits.
(1)