浏览代码

day05-javase

guyanqing 1 年之前
父节点
当前提交
0b146bd531

+ 1 - 0
JavaSE/.idea/compiler.xml

@@ -6,6 +6,7 @@
         <sourceOutputDir name="target/generated-sources/annotations" />
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
         <outputRelativeToContentRoot value="true" />
+        <module name="day05" />
         <module name="day04" />
       </profile>
     </annotationProcessing>

+ 1 - 0
JavaSE/.idea/misc.xml

@@ -5,6 +5,7 @@
     <option name="originalFiles">
       <list>
         <option value="$PROJECT_DIR$/day04/pom.xml" />
+        <option value="$PROJECT_DIR$/day05/pom.xml" />
       </list>
     </option>
   </component>

+ 16 - 0
JavaSE/day05/pom.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.sf</groupId>
+    <artifactId>day05</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+</project>

+ 14 - 0
JavaSE/day05/src/main/java/com/sf/Test1.java

@@ -0,0 +1,14 @@
+package com.sf;
+
+public class Test1 {
+    public static void main(String[] args) {
+        int[] aa = new int[5];
+        for (int i= 0 ;i <aa.length;i++){
+            aa[i] = i+1;
+            System.out.println("数组元素"+aa[i]);
+        }
+        System.out.println("========================================");
+        aa = null;
+        System.out.println(aa[2]);
+    }
+}

+ 92 - 0
JavaSE/day05/src/main/java/com/sf/Test2.java

@@ -0,0 +1,92 @@
+package com.sf;
+
+import javax.naming.InsufficientResourcesException;
+
+public class Test2 {
+    public static void main(String[] args) {
+        /**
+         * 有三个班级    每个班级有3个学生
+         */
+        String[] class1 = {"qq","ww","ee"};
+        String[] class2 = {"rr","tt","yy"};
+        String[] class3 = {"uu","ii","oo"};
+
+        /**
+         * 声明二维数组
+         * 1、元素的数据类型[][] 二维数组的名称;
+         * 2、元素的数据类型  二维数组名[][];
+         * 3、元素的数据类型[]  二维数组名[];
+         */
+        String[][] classTwo;   //推荐
+        String classTwo2[][];
+        String[] classTwo3[];
+
+        /**
+         * 将三个班级,每个班级中的三个同学  都放在一个二维数组里
+         * [][]
+         *      第一个中括号代表的是 二维数组中的第一个元素
+         *      第二个中括号代表的是  二维数组中的第一个元素(一维数组)中的每一个元素
+         */
+        String[][] className = {{"qq","ww","ee"},{"rr","tt","yy"},{"uu","ii","oo"}};
+        for (int k = 0; k<className.length;k++){
+            System.out.println("循环次数"+k);
+            for (int z = 0;z < className[k].length;z++){
+                String s = className[k][z];
+                System.out.println(s);
+                System.out.println("第一个元素的长度"+ className[k].length);
+
+            }
+        }
+
+        String name = className[0][0];
+//        System.out.println("qq"+name);
+//        System.out.println("yy===>"+className[1][2]);
+
+        String[][] className2 = new String[][]{{"qq","ww","ee"},{"rr","tt","yy"},{"uu","ii","oo"}};
+        String[][] className3;
+        className3 =  new String[][]{{"qq","ww","ee"},{"rr","tt","yy"},{"uu","ii","oo"}};
+
+        /**
+         * [1]  : 二维数组中 包含2个一维数组    行
+         * [2]  : 每个一维数组中的元素个数为3个  列
+         */
+        String[][]  arr = new String[2][3];
+        arr[0][0] = "张三0";
+        arr[0][1] = "张三1";
+        arr[0][2] = "张三2";
+//        第二个一维数组赋值
+        arr[1][0] = "张四0";
+        arr[1][1] = "张四1";
+        arr[1][2] = "张四2";
+
+        System.out.println(arr[1][1]);
+        /**
+         * 获取二维数组的长度    获取二维数组中一维数组(第一个元素)的的长度
+         */
+        int length = arr.length;
+        int length1 = arr[0].length;
+
+        System.out.println(length);
+        System.out.println("================="+length1);
+
+
+        /**
+         * 二维数组的遍历
+         */
+        String[][] name1 = new String[][]{{"qq","ww","ee"},{"rr","tt","yy"},{"uu","ii","oo"}};
+
+
+
+        int[][] xs = {{12,14,24},{23,18,35},{33,48,25},{27,28,35}};
+        int sum = 0;
+        int count = 0; //数组长度
+        for (int q = 0 ;q<xs.length;q++){
+            for (int e = 0 ;e <xs[q].length;e++){
+                sum+=xs[q][e];
+                count++;
+            }
+        }
+        System.out.println("总和为"+sum);
+        System.out.println("平均值"+sum/count);
+    }
+}

+ 46 - 0
JavaSE/day05/src/main/java/com/sf/Test3.java

@@ -0,0 +1,46 @@
+package com.sf;
+
+/**
+ * 杨辉三角
+ */
+public class Test3 {
+    /**
+     * @author 爱扣钉-陈晨
+     * @create 10:11
+     */
+        public static void main(String[] args) {
+
+            //1. 动态初始化的方式创建二维数组
+            int[][] yangHui = new int[10][];
+
+            for (int i = 0; i < yangHui.length; i++) {
+                yangHui[i] = new int[i + 1];
+
+                //2. 给数组元素赋值
+                // 2.1 给外层数组元素中的首元素和末元素赋值
+                yangHui[i][0] = yangHui[i][i] = 1;
+
+                //2.2 给外层数组元素中的非首元素和非末元素赋值(难)
+                //if(i > 1){ //从 i == 2 开始执行
+                for(int j = 1;j < yangHui[i].length - 1;j++){
+                    //非首元素和非末元素的角标范围
+                    yangHui[i][j] = yangHui[i-1][j-1] + yangHui[i-1][j];
+
+                }
+                //}
+            }
+
+
+            //3. 遍历二维数组
+            for (int i = 0; i < yangHui.length; i++) {
+                for (int j = 0; j < yangHui[i].length; j++) {
+                    System.out.print(yangHui[i][j] + "\t");
+                }
+
+                System.out.println();
+            }
+
+        }
+}
+
+

二进制
JavaSE/day05/target/classes/com/sf/Test1.class


二进制
JavaSE/day05/target/classes/com/sf/Test2.class


二进制
JavaSE/day05/target/classes/com/sf/Test3.class