Page 145 - CA_Blue( J )_Class10
P. 145
- If the score is between 70 and 79, the grade is 'C'.
- If the score is between 60 and 69, the grade is 'D'.
- If the score is below 60, the grade is 'F'.
John writes the following code to implement the grading system:
int score = 82;
char grade;
if (score >= 90)
{ grade = 'A'; }
else if (score >= 80)
{ grade = 'B'; }
else if (score >= 70)
{ grade = 'C'; }
else if (score >= 60)
{ grade = 'D'; }
else
{ grade = 'F'; }
System.out.println("Grade: " + grade);
What will be the output of the code?
a. Grade: A b. Grade: B
c. Grade: C d. Grade: D
3. Anindita is designing an ATM withdrawal system. The rules for withdrawal are as follows:
- The ATM can only dispense Rs. 20, Rs. 50, and Rs. 100 bills.
- If the requested amount is not a multiple of 20, print "Invalid amount".
- If the requested amount is greater than the available balance, print "Insufficient funds".
Anindita writes the following code to implement these rules:
int requestedAmount = 130;
int availableBalance = 500;
if (requestedAmount % 20 != 0)
{ System.out.println("Invalid amount"); }
else if (requestedAmount > availableBalance)
{ System.out.println("Insufficient funds"); }
else
{ availableBalance -= requestedAmount;
System.out.println("Please take your cash. Remaining balance: Rs. " + availableBalance);
}
What will be the output of the code?
a. Invalid amount
b. Insufficient funds
c. Please take your cash. Remaining balance: Rs. 370
d. Please take your cash. Remaining balance: Rs. 500
Ans. 1. b 2. b 3. a
143
Conditional Constructs in Java 143

