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+"\0\0");

     }

}

 

//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}};

 

posted on 2018-07-18 10:28  Postgre叮当牛i  阅读(132)  评论(0编辑  收藏  举报

导航