Question 1 - Simple Conditions
Create a console application that accepts two integer from the user and then displays if the values are equal or not equal.
Question 2 - Equality and relational operators
Modify the above application so that application uses the following condition to display the outputs
- If the first value is equal to second value then the system displays "First value is equal to second value"
- If the first value is not equal to second value then the system displays "First value is not equal to second value"
- If the first value is greater than second value then the system displays "First value is greater than second value"
- If the first value is less than second value then the system displays "First value is less than second value"
- If the first value is greater or equal second value then the system displays "First value is greater than or equal to second value"
- If the first value is less than or equal to second value then the system displays "First value is less than or equal to second value"
Question 3 - Conditional operators
Modify the above application to check for the following conditions
- If the first number is a even number then display "first number is an even number"
- If the second number is a even number then display "second number is an even number"
- if both numbers are even then display "Both Numbers are even"
- if both numbers are odd then display "Both Numbers are odd"
Question 4 - Arithmetic operator
Modify the above application to show the following information
- The sum of the two number
- Difference between two number (first minus second)
- The product of the two numbers
- Division (first divided by second)
Question 5 - Ternary Operator
Use a ternary operator in one line of code to replace first two if statement in Question 1.
That is, if two numbers are equal, system displays "The first number is equal to second number" otherwise it will display "The first number is not equal to second number"
Question 6 - Unary operators (prefix and postfix)
using the unary operators display the following,
- First number incremented by 1
- second number decremented by 1
Question 7 - Compound assignment
using the compound assignment do the following,
- Increment the first number by 5
- double the second number
Submit one .java file to W2Lab submission folder under assignments.
Comments
Post a Comment