Logical operators can simplify nested conditional statements. For example, can you rewrite this code using a single if statement?

if (x > 0) {
if (x < 10) {
System.out.println("positive single digit number.");
}
}

Respuesta :

In Java we have these wonderful things called logical operators. They are && and ||. The ampersand signs stand for and, while the straight lines stand for or.

To rewrite your code we can use the ampersand.

if (x > 0 && x < 10){

   System.out.println("Positive single digit number.");

}

I hope this helps!

ACCESS MORE