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

Java Class 9 Worksheet: If-Else Programs

Uploaded by

sidshah925
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)
74 views1 page

Java Class 9 Worksheet: If-Else Programs

Uploaded by

sidshah925
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

Java ICSE Class 9 Worksheet

Increment and Decrement Operators

Java ICSE Class 9 - If-Else Based Program Questions

Q1. Write a Java program to check whether a number is positive, negative or zero.

Q2. Write a program in Java to accept a number and check whether it is even or odd.

Q3. Write a Java program to input three numbers and print the greatest among them.

Q4. Write a Java program to check if a year entered by the user is a leap year or not.

Q5. Write a program to input marks of a student and display the grade as per the following:

- Marks >= 90: Grade A

- Marks >= 75 and < 90: Grade B

- Marks >= 60 and < 75: Grade C

- Marks < 60: Grade D

Q6. Write a Java program to accept the age of a person and check if they are eligible to vote (age >= 18).

Q7. Write a program to input the selling price and cost price of an item and print whether it's a profit, loss, or

no profit/loss.

Q8. Write a Java program to accept a character and check whether it is a vowel or consonant.

Q9. Write a program to input a number and check whether it is divisible by 5 and 11.

Q10. Write a program to input two numbers and a choice (1 for addition, 2 for subtraction, 3 for multiplication,

4 for division). Perform the selected operation using if-else.

Common questions

Powered by AI

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 .

You might also like