Educoder题⽬:Java⼊门-分⽀结构答案解析Java分⽀结构之 if…else
IfProject/src/step2/HelloIfStep2.java
package;
import Scanner;
public class HelloIfStep2 {
public static void main(String[] args){
Scanner input =new Scanner(System.in);
/******start******/
System.out.println("请输⼊学员成绩:");
int score = Int();
if(score>85){
System.out.println("优,⾮常棒!");
}else{
System.out.println("良,下次加油!");
}
/******end******/
}
}
if语句测试题
第1题答案:C
第2题答案:C
第3题答案:D
Java分⽀结构之多重if
IfProject/src/step3/HelloStep3.java
public static void main(String[] args){
System.out.println("星级成绩评定系统");
System.out.println("请输⼊成绩:");
Scanner sc =new Scanner(System.in);
/******start******/
int scope = sc.nextInt();
if(scope >=90){
System.out.print("*****五星成绩");
}else if(scope>=80&& scope<90){
System.out.print("****四星成绩");
}else if(scope>=70&& scope<80){
System.out.print("***三星成绩");
}else if(scope>=60&& scope<70){
System.out.print("**俩星成绩");
}else{
System.out.print("⽆星成绩");
}
/******end******/
}
}
Java分⽀结构之Switch IfProject/src/step4/HelloSwitch.java
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
System.out.println("请输⼊⽉份:");
int input = sc.nextInt();//获取输⼊的⽉份
//通过输⼊的⽉份来判断当前季节并输出
/*****start*****/
switch(input){
case3:
case4:
case5:
System.out.print(input+"⽉是春天");
break;
case6:
case7:
case8:
System.out.print(input+"⽉是夏天");
break;
case9:
case10:
case11:
System.out.print(input+"⽉是秋天");
break;
default:
System.out.print(input+"⽉是冬天");
break;
}
/*****end*****/
}
}
Switch语句测试题
第1题答案:CD
来吧,我是BOSS!
src/step5/Practice.java
package;
import Scanner;
public class Practice {
final static Scanner sc =new Scanner(System.in);//创建扫描仪//第⼀题
public void first(){
System.out.println("请输⼊⼈数:");
int input = sc.nextInt();//获取输⼊的数据
/*****start*****/
if(input >10){
System.out.println("打全场");
}else{
System.out.println("打半场");
}
/*****end*****/
}
//第⼆题
public void second(){
System.out.println("请输⼊今天星期⼏:");
int input = sc.nextInt();//获取输⼊的数据
/*****start*****/
if(input ==1){
System.out.println("今天吃⽶饭");
}else if(input ==2){
System.out.println("今天吃⽜排");
}else if(input ==2){
System.out.println("今天吃鸡排");
}else{
System.out.println("今天吃红烧⾁");
}
/*****end*****/
}
//第三题
public void third(){
System.out.println("请输⼊今天星期⼏:");
int input = sc.nextInt();//获取输⼊的数据
/*****start*****/
switch(input){
case1:
System.out.println("今天吃⽶饭");
break;
case2:
System.out.println("今天吃⽜排");
break;
case3:
System.out.println("今天吃鸡排");
break;
default:
java switch case stringSystem.out.println("今天吃红烧⾁");
break;
}
/*****end*****/
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。