guyanqing 1 жил өмнө
parent
commit
60b69912f2

+ 6 - 1
src/main/java/com/sf/day03/Method.java

@@ -37,7 +37,12 @@ public class Method {
     /**
      *
      * @param name   形参
-     * @return    参数列表不用(参数列表相同 数据类型不同)  方法名相同    重载方法
+     * @return    参数列表不用(参数列表相同 数据类型不同)  方法名相同
+     *重载方法
+     * 带有static修饰的方法    静态方法
+     * 优势:如果调用一个类中的一个方法,没有statis修饰时,我们需要创建对象  然后在调用方法
+     *  如果有static修饰,就可以直接通过类名.方法名()进行调用
+     *  Method.getInfoWithName();
      */
     public static String getInfoWithName(String name){  //
         String str = name+"我是方法的返回值";

+ 12 - 1
src/main/java/com/sf/day03/Test03.java

@@ -4,7 +4,18 @@ import java.util.Scanner;
 
 public class Test03 {
     public static void main(String[] args) {
-        Scanner scanner = new Scanner(System.in);
+        for (int j = 0;j <5; j++){
+            System.out.println(j);
+        }
 
+        int b = 1;
+        int count=0;
+        while(b<=88488600){
+            b *= 2;
+            count++;
+        }
+        System.out.println(count);
+
+        
     }
 }

+ 36 - 0
src/main/java/com/sf/day04/ArrayTest.java

@@ -0,0 +1,36 @@
+package com.sf.day04;
+
+/**
+ * 数组
+ */
+public class ArrayTest {
+    public static void main(String[] args) {
+        /*
+        数组的定义,两种方式没有任何区别
+         */
+
+        int[] a ;   //推荐  int  a ;
+        int b[] ;
+        String[] str;
+        double[]  array;
+
+        /**
+         * 数组初始化    静态初始化
+         */
+
+        String[] str2 = new String[]{"张三","lisi","..."};
+        int[]  aa = {1,2,3};
+
+        int[]  bb ;
+        bb = new int[]{1,2,3};
+        int[] cc = new int[]{1,2,3};
+        System.out.println("cc===="+cc);
+        System.out.println("aa===="+aa);
+
+//        int[] cc;
+//        cc = {1,2,3};  //错误
+
+
+
+    }
+}

+ 32 - 0
src/main/java/com/sf/day04/Test01.java

@@ -0,0 +1,32 @@
+package com.sf.day04;
+
+public class Test01 {
+
+    /**
+     * 求n的阶乘   递归
+     * eg:  5的阶乘   5*4*3*2*1
+     * @return
+     * 编写递归的时候  需要注意的事项: 避免死循环
+     * 场景   :  需要不断的自增   自己调自己的方法
+     * 例如::   文件夹下包含摄像头和文件夹,下一层文件夹下还包含摄像头和文件夹 ....
+     *           然你在当前文件夹名称后面显示当前文件夹下有多少个摄像头和文件夹(11/8)
+     *
+     */
+    public static int factorial(int n){
+        /**
+         *
+         */
+        if(n ==1){
+            return 1;
+        }
+        int sum = n * factorial(n - 1);
+        return sum;
+    }
+
+
+    public static void main(String[] args) {
+        //     int    factorial       =   20;
+        int factorial = factorial(3);
+        System.out.println(factorial);
+    }
+}

+ 61 - 0
src/main/java/com/sf/day04/Test02.java

@@ -0,0 +1,61 @@
+package com.sf.day04;
+
+/**
+ * 数组元素的访问和修改
+ */
+public class Test02 {
+    public static void main(String[] args) {
+        String[] str = new String[]{"张三","李四","王五"};
+        //                              0   1       2
+        //确定数组的长度    数组名.length
+        int strLength = str.length;
+        System.out.println(strLength);
+
+        /**
+         * 数组的下表从0开始     截止到  数组名.length-1
+         * 获取数组中的数据   数组名[索引/下标]
+         * 数组中元素的获取和修改
+         */
+        System.out.println("张三======"+str[0]);
+        System.out.println("李四======"+str[1]);
+        System.out.println("王五======"+str[2]);
+        str[0] = "赵六";
+        System.out.println("张三======"+str[0]);
+        System.out.println("李四======"+str[1]);
+        System.out.println("王五======"+str[2]);
+
+
+        int[] arr = {1,3,4,56,8,7,6,8,4,5,98,4,0,9,4};
+        System.out.println(arr.length);
+        System.out.println(arr[0]);
+        System.out.println(arr[1]);
+        System.out.println(arr[2]);
+        System.out.println(arr[3]);
+        System.out.println(arr[4]);
+        System.out.println(arr[5]);
+        System.out.println(arr[6]);
+        System.out.println(arr[7]);
+        System.out.println(arr[8]);
+        System.out.println(arr[9]);
+        System.out.println(arr[10]);
+        System.out.println(arr[11]);
+        System.out.println(arr[12]);
+        System.out.println(arr[13]);
+        System.out.println(arr[14]);
+
+        /**
+         * 遍历  数组的遍历
+         */
+        for (int i = 0;i<=14;i++){
+           int arra = arr[i];
+            System.out.println(arra);
+        }
+
+        //15个元素
+        for (int j = 0;j<=arr.length-1;j++){
+            System.out.println(arr[j]);
+        }
+
+
+    }
+}

BIN
target/classes/com/sf/day03/Method.class


BIN
target/classes/com/sf/day03/Test03.class


BIN
target/classes/com/sf/day04/ArrayTest.class


BIN
target/classes/com/sf/day04/Test01.class


BIN
target/classes/com/sf/day04/Test02.class