public class testif{
public static void main(String[] args) {
int i = 20;
if (i < 20){
System.out.println("<20");
System.out.println("<20");
}
else if (i < 40){
System.out.println("<40");
}
else if (i < 60){
System.out.println("<60");
}
else
System.out.println("i比60大");
}
}
编译的时候是javac testif.java
运行的时候是java testif
不是 java testif.class
操你给大爷记住了!
fot语句为如下形式:
for(表达式1;表达式2;表达式3){语句;……;}
执行过程
首先计算表达式一。接着执行表达式2、若表达式二的值=ture。则执行语句。接着计算表达式三的值。在判断表达式2的值。如此重复下去。直到表达式2的值为false
for语句中三个表达式都可以省略、
例子:
public class test{
public static void main(String args[]){
long result = 0;
long f = 1;
for ( int i = 1; i <= 10; i++ ){
f = f * i;
result = f + result;
}
System.out.println(result);
}
}
result = 1! + 2! + 3! + …… +10!
作业:
public class test1{
public static void main(String args[]){
long n = 0;
for ( int i = 1; i <= 100; i++ ){
n = n + i;
}
System.out.println("n=" + n);
}
}
n = 1 + 2 + 3 + …… +100 = 5050

