Help with writing if statements in Java? Question 1: -Write nested if statement
ID: 3822895 • Letter: H
Question
Help with writing if statements in Java?
Question 1:
-Write nested if statement that perform the following tests: If saleTransaction1 is greater than 2000 and saleTransaction2 is greater than 3000, if sale transaction2 is less than saleTransaction1 then display the “Transaction2” otherwise display the “Transaction1”
-Write an if statement that prints the message “The grade is B” if the variable score is greater or equal to 80 and less than 90
-Write an if statement that prints the message “The number is valid” if the variable number is within the range -32 through 273
Explanation / Answer
Write nested if statement that perform the following tests: If saleTransaction1 is greater than 2000 and saleTransaction2 is greater than 3000, if sale transaction2 is less than saleTransaction1 then display the “Transaction2” otherwise display the “Transaction1”
Answer:
if(saleTransaction1 > 2000 && saleTransaction2 > 3000 ) {
if(saleTransaction2 < saleTransaction1 ) {
System.out.println("Transaction2");
}
else{
System.out.println("Transaction1");
}
}
Write an if statement that prints the message “The grade is B” if the variable score is greater or equal to 80 and less than 90
Answer:
if(score >=80 && score < 90) {
System.out.println("The grade is B");
}
Write an if statement that prints the message “The number is valid” if the variable number is within the range -32 through 273
Answer:
if(number >= -32 && number <=273) {
System.out.println("The number is valid");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.