zoukankan      html  css  js  c++  java
  • 16年10月19号 3th 流程结构嵌套

    概要

    1.break and  continue

    2.100以内奇偶数

    3.九九乘法表

    4.3个数比大小

    例子

    1 break  结束当前代码体,结束当前代码块  | continue 继续 结束本次循环进行下次循环

       int stop = 4;                                    |  int stop = 4;                       

       for(int i=1;i<5;i++){                        |  for(int i=1;i<5;i++){        

     if(i == stop)                |   if(i == stop)

      break;                     |    contimue;

        System.out.print(i);                         |      System.out.print(i);

     }                     | }

     打印结果 123               |   打印结果 123 5

    2  100以内奇偶思路       1先用for遍历100, 2用if判断奇偶  打印输出

    public class   ji'ou{

      public static void main(String[] args){

        for(int i = 1;i<=10;i++){

            //奇偶判断 

            if(i%2!=0){

             //奇数

            System.out.print("奇数是"+i);

            }else{

            //打印偶数

            System.out.print("oshushi"+i);

              }

        }

      }

    }

    3.九九乘法表  思路  先实现正方形  在实现三角形   再将打印内容替换为变

     1.0  打印九行九列

       System.out.print("XXXXXXXX");

         System.out.print("XXXXXXXX"); 

       System.out.print("XXXXXXXX");

         System.out.print("XXXXXXXX");

            …………………………

       ………………………………

    2.0  for循环  打印九行九列

    for(int i=1;i<=9;i++){

        System.out.print("XXXXXXXX");

      }

    3.0  两个 for循环  打印九行九列

    for(int h=1;h<=9;h++){

        for(int l=1;l<=9;l++){

          System.out.print("X");

         }

             //换行

        System.out.println();

           }

    4.0   重要一部,变成三角形

      

    for(int h=1;h<=9;h++){

        for(int l=1;l<= h;l++){

          System.out.print("X");

         }

              System.out.println();

           }

    5.0 把打印内容换成变量

    for(int h=1;h<=9;h++){

        for(int l=1;l<= h;l++){

          System.out.print("a*b");

           System.out.print(h+"*"+l+"="+h*l); 

         }

           System.out.println();

           }

    先整100个数
    int num = 0;
    for(int i=1;i<=00;i++){

    if(i%3==0){
    System.out.print(i);
    //统计次数,break;
    num++;
    }
    if(num==5)
    break;
    }


    三个数比大小


    a在与c比大小
    a先与b比大小/

    b在与c比大小

    //比较a b的大小
    if(a>b){
    //如果a>b, 比较a c
    if(a>c){
    //输出a
    System.out.print(a);
    }else{
    //输出c
    System.out.print(c);
    }
    }else{
    //如果a<b, 比较b c
    if(b>c){
    //输出b
    System.out.print(b);
    }else{
    //输出c
    System.out.print(c);
    }
    }
    //三目运算 解决三个数比大小
    int e = (a>b?)(a>c?a:c):(b>c?b:c)
    System.out.prnt(e);

    //随机点菜宝    random()值为0.XX 所以要乘4 取整  并+1
    int f = (int)(Math.random()*4)+1;

  • 相关阅读:
    解决IE 下div与img重叠无法触发鼠标事件的问题
    四边相同阴影效果
    dedecms 获取文章发布时间和获取文章最后更新时间
    局域网访问网站
    HTML 5 的data-* 自定义属性
    yum 安装 influxdb/telegraf
    zabbix 监控 AWS-SQS 队列
    解决阿里云部署 office web apps ApplicationFailedException 报错问题
    jira集成fisheye代码深度查看工具安装绿色版
    阿里云ecs开启x11图形化桌面
  • 原文地址:https://www.cnblogs.com/amurzet/p/5980308.html
Copyright © 2011-2022 走看看