zoukankan      html  css  js  c++  java
  • java forwhileswitch语句持续更新

    1.while先判断,再执行;do while先执行,再判断。

    2.for的无限循环:for(;;){}

    3.java 菱形

    public class demo_diamond {
        public static void main(String [] args){
            for(int i=1;i<=4;i++){
                for(int j=1;j<=4-i;j++) {
                    System.out.print(" ");
                }
                for(int x=1;x<=2*i-1;x++){
                    System.out.print("*");
                }
                System.out.println();
    
    
    
                }
            for(int a=1;a<=3;a++){
                for(int c=1;c<=a;c++) {
                    System.out.print(" ");
                }
                for(int b=1;b<=7-2*a;b++){
                    System.out.print("*");
                }
                System.out.println();
    
    
                }
            }
    
            }

    4.java空心菱形

    public class demo_kongdiamond {
        public static void main(String[] args) {
            for (int i = 1; i <= 4; i++) {
                for (int j = 1; j <= 4 - i; j++) {
                    System.out.print(" ");
                }
                for (int x = 1; x <= 2 * i - 1; x++) {
                    if (x == 1 || x == 2 * i - 1) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
    
                }
    
                System.out.println();
    
    
            }
    
            for (int a = 1; a <= 3; a++) {
                for (int b = 1; b <= a; b++) {
                    System.out.print(" ");
                }
                for (int c = 1; c <= 7 - 2 * a; c++) {
                    if (c == 1 || c == 7 - 2 * a) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
    
                    }
    
                }
    
                System.out.println();
    
    
            }
    
    
        }
    }

     5.九九乘法表

    public class demo1_九九乘法表 {
        public static void main(String[] args){
            for(int i=1;i<=9;i++){
                for(int j=1;j<=i;j++){
                    System.out.print(i+"*"+j+"="+(i*j)+"	");
                }
                System.out.println();
            }
        }
    }

     6.break与continue

      二者相同:均能用于switch语句与loop语句;

      二者不同:break跳出当前循环,使用标识符能够跳出指定循环;continue终止本次循环,跳过直接开始下一循环。

    控制输出次数:

    public class demo_连续与终端 {
        public static void main(String[] args){
            int count=0;
            a:for(int i=1;i<=10;i++){
                if (i%3==0){
                    //break ;//输出两次
                    //continue ;//输出7次
                    System.out.println("java");//输出13次
                    count++;
    
    
                }
                count++;
                System.out.println(count);
                System.out.println("java");
            }
        }
    }
  • 相关阅读:
    [转载自 文顶顶]iOS开发UI篇—程序启动原理和UIApplication
    中专生自学Android到找到工作的前前后后
    HashCode与IEqualityComparer接口
    abp vnext使用记录之微服务
    asp.net core 外部认证多站点模式实现
    xamarin.android 绑定百度地图SDK遇到的问题
    asp.net core 之多语言国际化自定义资源文件
    asp.net core tags 扩展之 id 和 name
    asp.net 后台任务作业框架收集
    向量
  • 原文地址:https://www.cnblogs.com/resort-033/p/12914765.html
Copyright © 2011-2022 走看看