代码
package java第二个工程;
public class Test {
public static void main(String[] args) {
int i = 1;
//if else 语句
if(i>0) {
System.out.println("这是一个正整数");
}else if(i == 0){
System.out.println("这既不是正数也不是负整数");
}else {
System.out.println("这是一个负整数");
}
//switch 语句
switch(i) {
case 1:System.out.println("这是1");
break;
case -1:System.out.println("这是-1");
break;
default:System.out.println("不是1也不是-1");
}
//for循环语句
for(i = 0;i<=5;i++) {
System.out.println("我超帅!");
}
//while循环语句
while(i>0) {
System.out.println("别夸我帅啦~我会害羞的");
i--;
}
//do while循环语句
do {
System.out.println("谢谢夸奖");
i++;
}while(i<=0);
}
}
运行结果
这是一个正整数
这是1
我超帅!
我超帅!
我超帅!
我超帅!
我超帅!
我超帅!
别夸我帅啦~我会害羞的
别夸我帅啦~我会害羞的
别夸我帅啦~我会害羞的
别夸我帅啦~我会害羞的
别夸我帅啦~我会害羞的
别夸我帅啦~我会害羞的
谢谢夸奖
总结
这不是和C语言一模一样的嘛,没啥区别~~