zoukankan      html  css  js  c++  java
  • Java中循环与选择语句

     1 public class Ifelse{
     2     public static void main(String [] args){
     3         int score=98;
     4         if(score>=90&&score<=100)
     5             System.out.println("优秀");
     6         else if(score>=80&&score<90)
     7             System.out.println("良好");
     8         else if(score>=70&&score<80)
     9             System.out.println("还行");
    10         else if(score>=60&&score<70)
    11             System.out.println("及格");
    12         else if(score>=0&&score<60)
    13             System.out.println("不及格");
    14         else
    15             System.out.println("数据错误");
    16     }
    17 }

    1.if语句单独判断
    2,if else二重判断
    3,if else if else if else 多重判断
    4,switch(表达式){case 常量值: break;}
     a.switch中多个case后面的数值不可以重复
     b.switch后面括号表达式只能是byte/short/char/int/String/enum数据类型
     c.case语句前后顺序可以颠倒,break可省略,但会出现意想不到的效果(不会跳出switch)

    public class XunHuan{
        public static void main(String [] args){
            int sum=0;
            int sum2=0;
            int sum3=0;
            for(int i=0;i<=100;i+=2)
                sum+=i;
            System.out.println(sum);
            int j=0;
            while(j<=100){
                sum2+=j;
                j+=2;
            }
            System.out.println(sum2);
            int k=0;
            do{
                sum3+=k;
                k+=2;
            }while(k<=100);
            System.out.println(sum3);
            
            
        }
        
        
    } 

    三种循环输出1-100的偶数和

  • 相关阅读:
    在 mac iTerm2 中使用 cmd 终端
    在 jupyter 中添加菜单和自动完成功能
    Bash 和 Zsh 开启 vi-mode
    免密登录和远程执行命令
    图片的筛选
    win10 右键菜单很慢的解决方式
    ssh中的 Connection closed by ***
    NodeJS 获取网页源代码
    在 JSDOM v11 中使用jQuery
    kafaka学习
  • 原文地址:https://www.cnblogs.com/XiaoJin0/p/10527069.html
Copyright © 2011-2022 走看看