Browse Source

javase-dayo4

guyanqing 1 year ago
parent
commit
835356a206

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
.idea/VIPQ.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 11 - 0
.idea/modules.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/VIPQ.iml" filepath="$PROJECT_DIR$/.idea/VIPQ.iml" />
+      <module fileurl="file://$PROJECT_DIR$/JavaSE/day01/day01.iml" filepath="$PROJECT_DIR$/JavaSE/day01/day01.iml" />
+      <module fileurl="file://$PROJECT_DIR$/JavaSE/day02/day02.iml" filepath="$PROJECT_DIR$/JavaSE/day02/day02.iml" />
+      <module fileurl="file://$PROJECT_DIR$/JavaSE/day03/day03.iml" filepath="$PROJECT_DIR$/JavaSE/day03/day03.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

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

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <annotationProcessing>
+      <profile name="Maven default annotation processors profile" enabled="true">
+        <sourceOutputDir name="target/generated-sources/annotations" />
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+        <outputRelativeToContentRoot value="true" />
+        <module name="day04" />
+      </profile>
+    </annotationProcessing>
+  </component>
+</project>

+ 20 - 0
JavaSE/.idea/jarRepositories.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RemoteRepositoriesConfiguration">
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Central Repository" />
+      <option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="jboss.community" />
+      <option name="name" value="JBoss Community repository" />
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+    </remote-repository>
+  </component>
+</project>

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

@@ -1,5 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/day04/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>

+ 16 - 0
JavaSE/day04/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>day04</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+</project>

+ 55 - 0
JavaSE/day04/src/main/java/com/sf/Day04.java

@@ -0,0 +1,55 @@
+package com.sf;
+
+public class Day04 {
+    public static void main(String[] args) {
+        int a = 1;
+        a=2;
+        /**
+         * 定义数组
+         *  语法:数据类型[] 数组的变量名
+         *  定义了一个数据类型为int类型,变量名为arr的整形数组
+         */
+        int[] arr;
+
+        /**
+         * 定义数组的方式二
+         * 数据类型 变量名[];
+         * 定义了一个int类型的变量,变量名是arr数组
+         */
+        int arr2[];
+
+        double[] aa;
+        double bb[];
+        String[] cc;  //推荐
+        String dd[];
+
+/**
+ * 数组的静态初始化,
+ * 语法:数据类型[] 变量名 = new 数据类型[]{数据1,数据2,数据3,…};
+ */
+        int[]  ee = new int[]{1,2,3,4};
+
+
+        /**
+         * int[] arr;
+         * arr = new int[]{1,2,3,4,5};//正确
+         */
+        int[] abc;
+        abc = new int[]{5,6,7,8};
+
+
+        /**
+         * 简化格式:
+         * 数据类型[] 变量名 = {数据1,数据2,数据3,…};
+         */
+        int[] ff = {1,2,3};   //常用  推荐
+        String[] person = {"qq","ww","ee"};
+        String[] person1 = new String[]{"qq","ww","ee"};
+        int[] gg;
+        gg= new int[]{1, 2, 3};
+
+
+
+    }
+
+}

+ 12 - 0
JavaSE/day04/src/main/java/com/sf/Test1.java

@@ -0,0 +1,12 @@
+package com.sf;
+
+public class Test1 {
+    public static void main(String[] args) {
+        int[] arr = {1,2,3,4,5};
+        char[] word = {'h','e','l','l','o'};
+        String[] heros = {"袁隆平","邓稼先","钱学森"};
+        System.out.println(arr);
+        System.out.println(word);
+        System.out.println(heros);
+    }
+}

+ 41 - 0
JavaSE/day04/src/main/java/com/sf/Test2.java

@@ -0,0 +1,41 @@
+package com.sf;
+
+public class Test2 {
+    public static void main(String[] args) {
+
+
+        String[] str = {"电视剧1", "电视剧2", "电视剧3", "电视剧4", "电视剧5", "电视剧6"};
+
+        String[] subject = {"学科1", "学科2", "学科3", "学科4", "学科5", "学科6"};
+
+        int[] score = {99, 98, 97, 96, 95};
+        int length = score.length;
+//        System.out.println("数组的长度"+length);
+
+        /**
+         * 数组名[索引/下标]
+         */
+        String[] person = {"张三","李四","王五","赵六","孙七","李八","王九"};
+        System.out.println("当前数组的长度"+person.length);
+        String zs = person[0]; //张三
+        System.out.println(zs);
+        String ls = person[1]; //李四
+        System.out.println(ls);
+        String ww = person[2]; //王五
+        System.out.println(ww);
+//        System.out.println(person[3]);
+
+//        //张三和王五换个位置
+//        person[0]="王五";
+//        person[2]="张三";
+//        System.out.println("更改后的"+person[2]);
+//
+        System.out.println(person.length);
+        for (int i = 0 ;i< person.length;i++){
+            String person1 = person[i];
+            System.out.println(person1);
+        }
+
+
+    }
+}

+ 26 - 0
JavaSE/day04/src/main/java/com/sf/Test3.java

@@ -0,0 +1,26 @@
+package com.sf;
+
+public class Test3 {
+    /**
+     * 求和   求平均值
+     * @param args
+     */
+    public static void main(String[] args) {
+        int[] arr = {4,5,6,1,9};
+        int sum = 0;
+        for (int i=0 ; i< arr.length;i++){
+            sum += arr[i];
+        }
+        System.out.println("当前总和==="+sum);
+        //平均值  sum/arr.length
+        if(arr.length > 0){
+            int avg = sum/arr.length ;
+            System.out.println("当前数组的平均值==>"+avg);
+        }else {
+            System.out.println("当前数组为空");
+        }
+
+
+
+    }
+}

+ 21 - 0
JavaSE/day04/src/main/java/com/sf/Test4.java

@@ -0,0 +1,21 @@
+package com.sf;
+
+public class Test4 {
+    public static void main(String[] args) {
+        int[] scores = {5,4,6,8,9,0,1,2,7,3};
+        int max = scores[0];
+        int min = scores[0];
+        int sum = 0;
+        for(int i = 0;i < scores.length;i++){
+            if(max < scores[i]){
+                max = scores[i];
+            }
+            if(min > scores[i]){
+                min = scores[i];
+            }
+            sum += scores[i];
+        }
+        double avg = (double)(sum - max - min) / (scores.length - 2);
+        System.out.println("选手去掉最高分和最低分之后的平均分为:" + avg);
+    }
+}

+ 41 - 0
JavaSE/day04/src/main/java/com/sf/Test5.java

@@ -0,0 +1,41 @@
+package com.sf;
+
+public class Test5 {
+    public static void main(String[] args) {
+        /**   动态初始化
+         * 数组存储的元素的数据类型[] 数组名字 = new 数组存储的元素的数据类型[长度];
+         * 或
+         * 数组存储的数据类型[] 数组名字;
+         * 数组名字 = new 数组存储的数据类型[长度];
+         */
+        int[] aa = new int[3];
+        int[] bb;
+        bb = new int[4];
+//        for (int i =0;i<aa.length;i++ ){
+//            aa[i]=1;
+//        }
+            aa[0]=1;
+            aa[1]=2;
+            aa[2]=3;
+        for (int i =0;i<aa.length;i++ ){
+            System.out.println(aa[i]);
+        }
+
+        /*
+        基本数据类型
+         */
+        int[] vv = new int[5];
+        for (int i =0;i<vv.length;i++){
+            System.out.println(vv[i]);
+        }
+
+
+        /**
+         * 包装类
+         */
+        Integer[] mm = new Integer[5];
+        for (int i =0;i<mm.length;i++){
+            System.out.println(mm[i]);
+        }
+    }
+}

+ 21 - 0
JavaSE/day04/src/main/java/com/sf/Test6.java

@@ -0,0 +1,21 @@
+package com.sf;
+
+public class Test6 {
+    public static void main(String[] args) {
+        int[][] aa={{12,14,24},{23,18,35},{33,48,25},{27,28,35}};
+
+        int sum = 0;
+        int time  = 0;
+        for (int i =0;i<aa.length;i++){
+            for (int j = 0; j<aa[i].length;j++){
+               int bb = aa[i][j];
+               sum += bb;
+               time++;
+            }
+        }
+        System.out.println("sum==="+sum);
+        System.out.println("time==="+time);
+        System.out.println("平均值==="+sum/time);
+    }
+
+}