if语句简单,其原理我不必赘述。
if语句小代码如下所示:
//if循环语句
public class IfLoop {
public static void main(String[] args) {
double i = 6 * Math.random();
double j = 6 * Math.random();
double k = 6 * Math.random(); // 6 * Math.random()是何含义???
int count = (int)(i + j + k);
if(count > 15) {
System.out.println("今天手气不错。(^__^)");
}
if (count >= 10 && count <= 15) {
System.out.println("今天手气很一般。");
}
if(count < 10) {
System.out.println("今天手气不怎么滴!!!");
}
System.out.println("得了" + count + "分");
}
}
输出结果为:
今天手气很一般。
得了11分
备注:以上输出的结果为一随机结果,该if小代码其结果不唯一,有多种不同结果。