if()else + switch用法


import java.util.Scanner;
class test{
 public static void main(String[] args){
/*
  //if()eles()用法
  String str="星期一"; //定义str
  if (str=="星期一") //判断str
  {
   System.out.println("今天是 "+str+" 今天学习java"); //输出
  }else if (str=="星期二")
  {
   System.out.println("今天是 "+str+"今天学习c++");
  }else if (str=="星期三")
  {
   System.out.println("今天是 "+str+"今天学习c#");
  }else if (str=="星期四")
  {
   System.out.println("今天是 "+str+"今天学习andriod");
  }else if (str=="星期五")
  {
   System.out.println("今天是 "+str+"今天学习php");
  }else
  {
   System.out.println("今天是没课放假啦!");
  }
  String str1="星期一";
  String str2=new String("星期一");
  boolean b=str1.equals(str2);
  System.out.print(b);
 
  */
   // 键盘输入+switch用法
  System.out.print("请输入:-----\n");
  Scanner sc=new Scanner(System.in); //定义键盘输出对象
  int i=sc.nextInt();
  int num=i/10;
  if (num>10||num<0) //判断输入数大于100或小于0
  {
   System.out.print("输入错误\n");
   System.out.print("请重新输入(0~100)\n");
    i=sc.nextInt(); //如果超出重新接收
     num=i/10;
    switch (num) //SWITCH循环
   {
   case 10:
    System.out.print("NB");
    break;
   case 9:
    System.out.print("A");
    break;
   case 8:
    System.out.print("B");
    break;
   case 7:
    System.out.print("c");
    break;
   case 6:
    System.out.print("D");
    break;
   case 5:
    System.out.print("不及格");
    break;
   default : //6>num>10均显示"不及格"
    System.out.print("输入错误");
    break;
   }
  }else{
   
   switch (num) //SWITCH循环
   {
   case 10:
    System.out.print("NB");
    break;
   case 9:
    System.out.print("A");
    break;
   case 8:
    System.out.print("B");
    break;
   case 7:
    System.out.print("c");
    break;
   case 6:
    System.out.print("D");
    break;
   case 5:
    System.out.print("不及格");
    break;
   default : //6>num>10均显示"不及格"
    System.out.print("输入错误");
    break;
   }
  }
 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值