• 2018-07-16博客


    Scanner scan1=new Scanner(System.in);

             while (true)

             {

                  System.out.println("1.新增");

                  System.out.println("2.修改");

                  System.out.println("0.退出");

                  int scan1int=scan1.nextInt();

                  if(scan1int==1){

                       System.out.println("1.新增");

                       break;

                  }else if(scan1int==2){

                       System.out.println("2.修改");

                       break;

                  }else{

                       System.out.println("0.退出");

                       break;

                  }

             }

    //2阶段项目页面就是这样打印出来的!!!

    练习一下打印星星!!!

    import java.util.Scanner;

    class  Demo07

    {

         public static void main(String[] args)

         {

             /*

             Scanner scan1=new Scanner(System.in);

             while (true)

             {

                  System.out.println("1.新增");

                  System.out.println("2.修改");

                  System.out.println("0.退出");

                  int scan1int=scan1.nextInt();

                  if(scan1int==1){

                       System.out.println("1.新增");

                       break;

                  }else if(scan1int==2){

                       System.out.println("2.修改");

                       break;

                  }else{

                       System.out.println("0.退出");

                       break;

                  }

             }

             */

             //break和continue区别:

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

             {

                  if (i==3)

                  {

                       break; //跳出循环

                       //continue; //跳出本次循环,执行下一次循环!

                  }

                  System.out.println(i);

             }

         }

    }

    标记:帮助break跳出外层循环!

    /*

             Scanner scan1=new Scanner(System.in);

             while (true)

             {

                  System.out.println("1.新增");

                  System.out.println("2.修改");

                  System.out.println("0.退出");

                  int scan1int=scan1.nextInt();

                  if(scan1int==1){

                       System.out.println("1.新增");

                       break;

                  }else if(scan1int==2){

                       System.out.println("2.修改");

                       break;

                  }else{

                       System.out.println("0.退出");

                       break;

                  }

             }

             */

             //break和continue区别:

             /*

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

             {

                  if (i==3)

                  {

                       break; //跳出循环

                       //continue; //跳出本次循环,执行下一次循环!

                  }

                  System.out.println(i);

             }

             */

             /*

             System.out.println("1--7的数字!");

             Scanner scan1=new Scanner(System.in);

             int scan1int=scan1.nextInt();

             switch(scan1int){

                  case 1:

                  case 2:

                  case 3:

                  case 4:

                  case 5:

                       System.out.println("工作日");

                       break;

                  case 6:

                  case 7:

                       System.out.println("休息日");

                       break;

                  default:

                       System.out.println("超出范围");

                       break;

             }

             */

             //System.out.println(Math max(3,4));

             /*

             int[] newint=new int[3];

             newint[0]=1;

             newint[1]=2;

             newint[2]=3;

             */

             int[] oldint={1,2,3,4,5,6,7,8,9,0};

             /*

             System.out.println(newint[0]);

             System.out.println(newint[1]);

             System.out.println(newint[2]);

             //下面这段代码提示:java.lang.ArrayIndexOutOfBoundsException(越界异常)!

             System.out.println(newint[3]);

             */

             //数组遍历:

             for(int i=0;i<oldint.length;++i){

                  System.out.println(oldint[i]);

             }

    //Math方法:

    System.out.println(Math.max(3,4));

    max:最大值/min:最小值!

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

         String j=i+"";

         if(j.indexOf("7")>=0){

             continue;

         }else{

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

         }

    }

    //Str.indexOf("Test"):返回字符串Str中包含Test这几个字的下标!

    流程控制:

    IF/IF-ELSE/IF-ELSE IF-ELSE

    Switch-Case

    循环语句:

    FOR/WHILE/DO WHILE

    //善用BREAK/CONTINUE

    //数组:

    数组是指一组数据的集合,数组中的每个数据被称作元素!在数组中可以存放任意类型的元素,但同一个数组里存放的元素类型必须一致!

    //定义格式:

    数据类型[] 数组名=new 数据类型[元素个数或数组长度];

    //静态初始化格式:

    类型[] 数组名 = new 类型[]{元素,元素,……};

    类型[] 数组名 = {元素,元素,元素,……};      

    数组越界异常:每个数组的索引都有一个范围,即0~length-1!在访问数组的元素时,索引不能超出这个范围,否则程序会报错!//ArrayIndexOutOfBoundsException

    空指针异常:在使用变量引用一个数组时,变量必须指向一个有效的数组对象,如果该变量的值为NULL,则意味着没有指向任何数组,此时通过该变量访问数组的元素会出现空指针异常!//NullPointerException

    二维数组定义格式:

    ①   int[][] testArr=new int[5][5];

    ②   int[][] testArr=new int[5][]; //不指定二维数组内子数组的长度!

    ③   int[][] testArr={{1,2,3},{4,5,6},{7,8,9}};

  • 相关阅读:
    android学习——android项目的的目录结构
    android学习——android项目的的目录结构
    LA 4670 Dominating Patterns (AC自动机)
    HDU 2089 不要62 (递推+暴力或者数位DP)
    HDU 2504 又见GCD (最大公因数+暴力)
    HDU 2136 Largest prime factor (素数打表。。。)
    HDU 2138 How many prime numbers (判素数,米勒拉宾算法)
    HDU 3177 Crixalis's Equipment (贪心,差值)
    HDU 1718 Rank (排序)
    HDU 1716 排列2 (格式问题+排列)
  • 原文地址:https://www.cnblogs.com/postgredingdangniu/p/9327721.html
Copyright © 2020-2023  润新知