Here's a simple example of how to use the Java if-else statement:

int num = 10;

if (num > 0) {
   System.out.println(num + ' is a positive number.');
}
 else {
   System.out.println(num + ' is a negative number.');
}

This code checks if the variable 'num' is greater than 0. If it is, the code inside the 'if' block will execute, printing out that 'num' is positive. If 'num' is not greater than 0 (meaning it's 0 or negative), the code inside the 'else' block will execute, printing out that 'num' is negative.

Java if-else Statement: A Simple Example with Code

原文地址: https://www.cveoy.top/t/topic/lEBt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录