zoukankan      html  css  js  c++  java
  • Java循环

    Java 循环

    Java中循环方法
    1.while循环
    package com.run;
    //这是个类
    public class Demo04 {
    //这是个run方法
    public void run(){
    int i = 10 ;
    while (i<=100){
    System.out.print(i + " " );
    i++;
    }
    }
    public static void main(String[] args) {
    Demo04 S = new Demo04();
    S.run();
    }
    }
    #循环至100结束
    2.do--------while循环
    #do -----while和while之间只是一个先进入循环一个后进入循环
    package com.run;
    //这是个类
    public class Demo04 {
    public void alxs(){
    int x = 10 ;
    do{
    System.out.println(x);
    x++;
    }while (x<100);
    }
    public static void main(String[] args) {
    Demo04 x = new Demo04();
    x.alxs();
    }
    }
    3.for循环
    package com.run;
    //这是个类
    public class Demo04 {
    public void css(){
    for (int i = 0; i < 100 ; i++) {
    System.out.println(i);
    }
    }
    public void js(){
    int [] i = {1,2,3,4,5,6,7,8,9,10,20,30};
    for (int j = 0; j < 12 ; j++) {
    System.out.println(i[j]);
    }
    }
    public static void main(String[] args) {
    Demo04 x = new Demo04();
    x.css();
    x.js();
    }
    }
    4.break关键字
    #当条件满足break关键字的条件即可跳出循环,即终止程序
    5.continue关键字
    #当条件满足时即跳出当前条件的循环
  • 相关阅读:
    Python通过多线程实现 `异步`
    Linux(六) 处理用户输入
    Linux(五) 更多结构化命令
    Linux(四) 使用结构化命令
    Linux(三) 科学计算
    Linux(二) Shell脚本
    python 登陆接口
    学习的小建议
    干货
    ThinkPhp5 自定义异常处理类
  • 原文地址:https://www.cnblogs.com/DB-MYSQL/p/14221504.html
Copyright © 2011-2022 走看看