Java Class 9 Worksheet: If-Else Programs
Java Class 9 Worksheet: If-Else Programs
In Java, the logic used to determine grades from marks involves a series of conditional statements that compare the student’s marks to predefined thresholds. If the marks are greater than or equal to 90, the grade is A; if they are between 75 and 89, the grade is B; if they fall between 60 and 74, the grade is C; and if they are less than 60, the grade is D .
To check voting eligibility in Java based on age, use an 'if' condition to evaluate whether the age of the person is 18 or older. If the condition is true, the person is eligible to vote; otherwise, they are not eligible .
A Java framework for processing basic arithmetic operations can be structured using 'if-else' statements based on user input. After taking two numbers and a choice as input, implement logic for each operation: if the input is 1, perform addition; if 2, subtract; if 3, multiply; and if 4, divide. This provides a structured method for executing user-selected operations .
To compare three numbers in Java and find the greatest one, use nested if-else statements. Begin by comparing the first and second numbers to find the larger one, then compare the result with the third number to establish which is the greatest. This approach ensures each number is checked against the others sequentially .
The algorithm to determine if a year is a leap year involves evaluating a few conditions: 1) A leap year is divisible by 4. 2) If it is divisible by 100, it must also be divisible by 400 to be a leap year. In Java, these can be combined in a conditional statement using the 'if' statement to check the conditions in sequence, ensuring logical order in checks .
In Java, a number is determined to be even or odd using the modulus operator (%). If a number modulo 2 yields 0, it is even; otherwise, it is odd. This simple condition, implemented with an 'if-else' structure, effectively differentiates even numbers from odd numbers .
To determine whether a given integer is positive, negative, or zero using Java, we need to use conditional statements. In Java, we can implement this by checking the value of the number with if-else statements. If the number is greater than zero, it is positive; if it is less than zero, it is negative; otherwise, it is zero .
A Java solution to compute transaction outcomes involves comparing the selling price to the cost price using 'if-else' statements. If the selling price is greater than the cost price, it indicates a profit. Conversely, if it is lesser, it signals a loss. If both are equal, there is neither profit nor loss .
To detect if a number is divisible by both 5 and 11 in Java, use the modulus operation in a conditional 'if' statement to check if the number modulo 5 and the number modulo 11 both return 0. This ensures that the number satisfies divisibility criteria for both 5 and 11 simultaneously .
Java can assess whether a year is a leap year by employing a sequence of conditional checks: verify if the year is divisible by 4 and not divisible by 100 unless it is also divisible by 400. This utilizes 'if-else' statements to efficiently filter years meeting leap year criteria .