19.根据名次奖励

import java.util.Scanner;


public class Main {
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("请输入您的名次");
int vip =input.nextInt();

if (vip<=3){
if (vip==1){
System.out.print("参加夏令营");
}else if(vip==2){
System.out.print("奖励笔记本");
}else if(vip==3){
System.out.print("移动硬盘");
}
}else{

System.out.println("没有任何奖励");
}
}

}

上面是自己写的~和上篇文章使用的代码类似,就是多重if 选择结构

下面是课本的写法,没有嵌套if

import java.util.Scanner;


public class Main {
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("请输入您的名次");
int vip =input.nextInt();


if (vip==1){
System.out.print("参加夏令营");
}else if(vip==2){
System.out.print("奖励笔记本");
}else if(vip==3){
System.out.print("移动硬盘");

}else{

System.out.println("没有任何奖励");
}

}
}



posted @ 2011-12-19 23:42  馨梦域名主机服务中心  阅读(252)  评论(0编辑  收藏  举报
官方推出免费静态网页空间,适合大企业展示和个人展示类空间。欢迎联系QQ908898668申请。