Revision-4
Given two numbers A and B, print the largest.
Step 1: Accept the input values for A and B.
Step 2: Compare the values of A and B using an "if" statement.
Step 3: If A is greater than B, print A as the largest number. Otherwise, print B as the largest number.
Step 4: End the program.
Given a number N, check if it is divisible by 3.
Step 1: Accept the input value for N.
Step 2: Calculate the remainder by dividing N by 3 using the modulo operator (%).
Step 3: Check if the remainder is zero.
Step 4: If the remainder is zero, print that N is divisible by 3. Otherwise, print that N is not divisible by 3.
Step 5: End the program.
The ternary operator, also known as the conditional operator, is a shorthand alternative to the traditional if-else statement in Java. It allows us to evaluate a condition and choose between two expressions based on the result of that condition.
Syntax : condition ? expression1 : expression2
Example : string result = ( number >0 ) ? "Positive" : "Negative"
Given a number N, check if it is odd or even.
Step 1: Accept the input number N.
Step 2: Calculate the remainder by performing the operation N % 2.
Step 3: If the remainder is 0, the number is even. Otherwise, it is odd.
Step 4: Print the result.