标签:
------- android培训、java培训、期待与您交流! ----------
1.选择结构if语句格式及其使用
A:if语句的格式:
1 import java.util.Scanner; 2 class Demo_If { 3 public static void main(String[] args) { 4 Scanner sc = new Scanner(System.in); //键盘输入, 5 while(true) { 6 System.out.println("请您输入成绩"); //提示输入 7 int a = sc.nextInt(); //键盘输入用int类型接收 8 if (a>100|a<0) { //死循环,方便测试 9 System.out.println("您输入的成绩有误"); 10 }else if (a>=90&a<=100) { 11 System.out.println("A等"); 12 }else if (a>=80&a<90) { 13 System.out.println("B等"); 14 }else if (a>=70&a<80) { 15 System.out.println("C等"); 16 }else if (a>=60&a<70) { 17 System.out.println("D等"); 18 }else if (a<60) { 19 System.out.println("E等"); 20 }else { 21 System.out.println("您输入的成绩有误"); 22 } 23 } 24 } 25 }
1 import java.util.*; 2 class Dome_If3{ 3 public static void main(String[] args) { 4 //System.out.println("Hello World!"); 5 Scanner sc =new Scanner(System.in); //键盘录入 6 while(true) { //死循环方便测试 7 System.out.println("请您 输入要转换的星期数"); //键盘录入提示 8 in week = sc.nextInt(); 9 switch(week) { 10 case 1: 11 System.out.println("星期1"); 12 break; 13 case 2: 14 System.out.println("星期2"); 15 break; 16 case 3: 17 System.out.println("星期3"); 18 break; 19 case 4: 20 System.out.println("星期4"); 21 break; 22 case 5: 23 System.out.println("星期5"); 24 break; 25 case 6: 26 System.out.println("星期6"); 27 break; 28 case 7: 29 System.out.println("星期天"); 30 break; 31 default: 32 System.out.println("您输入的数字有误,请重新输入"); 33 } 34 } 35 } 36 }
------- Windows Phone 8手机开发、.Net培训、期待与您交流! -------
标签:
原文地址:http://www.cnblogs.com/bluesky365/p/5631517.html