diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..267c321 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# 项目排除路径 +/out/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31ee1fe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fc53374 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/code.iml b/code.iml new file mode 100644 index 0000000..e13cb1e --- /dev/null +++ b/code.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/java/java.iml b/java/java.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/java/java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Demo01.java b/java/src/com/susu2568/array/Demo01.java similarity index 95% rename from Demo01.java rename to java/src/com/susu2568/array/Demo01.java index c007106..1eebb1a 100644 --- a/Demo01.java +++ b/java/src/com/susu2568/array/Demo01.java @@ -1,20 +1,20 @@ -package com.susu2568.array; - -public class Demo01 { - public static void main(String[] args) { -// int[] nums; -// nums = new int[10]; - int[] nums = new int[10]; - nums[0] = 1; - nums[1] = 1; - nums[2] = 1; - nums[3] = 1; - int sum = 0; - for (int i = 0; i -1 ; i--) { +// System.out.println(array[i]); + for (int i = 1; i < args.length-1 ; i++) { + System.out.println(array[-i]); + } + } + } + diff --git a/java/src/com/susu2568/array/Demo03.java b/java/src/com/susu2568/array/Demo03.java new file mode 100644 index 0000000..6169fe8 --- /dev/null +++ b/java/src/com/susu2568/array/Demo03.java @@ -0,0 +1,29 @@ +package com.susu2568.array; +import java.util.Arrays; +public class Demo03 { + public static void main(String[] args) { + int[] a = {1,2,3,40,900,500,4}; + + + //打印数组元素Arrays.toString(a) + System.out.println(Arrays.toString(a)); + + + //数组进行排序 升序 + Arrays.sort(a); + System.out.println(Arrays.toString(a)); + + //冒泡排序 + int temp = 0; + for (int i = 0; i < a.length-1; i++) { + for (int j = 0; j < a.length-1-i; j++) { + if (a[j+1] >a[j]){ + temp = a[j]; + a[j]= a[j+1]; + a[j+1] = temp; + } + } + } + System.out.println(Arrays.toString(a)); + } +} diff --git a/java/src/com/susu2568/array/Demo04.java b/java/src/com/susu2568/array/Demo04.java new file mode 100644 index 0000000..507573e --- /dev/null +++ b/java/src/com/susu2568/array/Demo04.java @@ -0,0 +1,100 @@ +package com.susu2568.array; + +import java.sql.SQLOutput; + +public class Demo04 { + public static void main(String[] args) { + int sum = 0; + int[][] array1 = new int[11][11]; + array1[1][2] = 1; + array1[2][3] = 2; + System.out.println("输出原始的数组"); + + for (int [] ints : array1){ + for (int anInt : ints){ + System.out.print(anInt + "\t"); + } + System.out.println(); + } + //输出有效值个数 + for (int i = 0; i < 11; i++) { + for (int j = 0; j < 11; j++) { + if (array1[i][j] != 0){ + sum++; + } + } + } + System.out.println("有效值的个数:"+sum); + + int[][] array2 = new int[sum+1][3]; + array2[0][0] = 11; + array2[0][1] = 11; + array2[0][2] = sum; + + int count=0 ; + for (int i = 0; i < array1.length; i++) { + for (int j = 0; j < array1[i].length; j++) { + if (array1[i][j] != 0){ + count++; + array2[count][0] = i; + array2[count][1] = j; + array2[count][2] = array1[i][j]; + } + + } + + } + System.out.println("稀疏数组"); + for (int i = 0; i < array2.length; i++) { + System.out.println(array2[i][0]+"\t" + +array2[i][1]+"\t" + +array2[i][2]); + } + + //还原 + int[][] array3 = new int[array2[0][0]][array2[0][1]]; + + for (int i = 1; i < array2.length; i++) { + array3[array2[i][0]][array2[i][1]] = array2[i][2]; + } + + System.out.println("输出还原的数组"); + for (int [] ints : array3){ + for (int anInt : ints){ + System.out.print(anInt + "\t"); + } + System.out.println(); + } + } +} + + +//out:输出原始的数组 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 1 0 0 0 0 0 0 0 0 +//0 0 0 2 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//有效值的个数:2 +//稀疏数组 +//11 11 2 +//1 2 1 +//2 3 2 +//输出还原的数组 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 1 0 0 0 0 0 0 0 0 +//0 0 0 2 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 +//0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/java/src/com/susu2568/base/Doc.java b/java/src/com/susu2568/base/Doc.java new file mode 100644 index 0000000..fdee35d --- /dev/null +++ b/java/src/com/susu2568/base/Doc.java @@ -0,0 +1,19 @@ +package com.susu2568.base; +/** +* @author susu2568 + * @version 1.0 + * @since 1.15 + */ +public class Doc { + String name; + + /** + * + * @param name + * @return + * @throws Exception + */ + public String test(String name) throws Exception{ + return name; + } +} diff --git a/java/src/com/susu2568/base/demo01.java b/java/src/com/susu2568/base/demo01.java new file mode 100644 index 0000000..2d87f75 --- /dev/null +++ b/java/src/com/susu2568/base/demo01.java @@ -0,0 +1,13 @@ +package com.susu2568.base; + +public class demo01 { + public static void main(String[] args) { + int a = 1_0000_0000; + System.out.println(a); + } + public void add(){ + + } +} +//out 100000000 + diff --git a/java/src/com/susu2568/base/demo02.java b/java/src/com/susu2568/base/demo02.java new file mode 100644 index 0000000..b54afc5 --- /dev/null +++ b/java/src/com/susu2568/base/demo02.java @@ -0,0 +1,10 @@ +package com.susu2568.base; + +public class demo02 { + int age=10; + public static void main(String[] args) { + demo02 demo02 = new demo02(); + System.out.println(demo02.age); + } +} +// 实例变量的调用 \ No newline at end of file diff --git a/java/src/com/susu2568/base/demo03.java b/java/src/com/susu2568/base/demo03.java new file mode 100644 index 0000000..99ff8d2 --- /dev/null +++ b/java/src/com/susu2568/base/demo03.java @@ -0,0 +1,9 @@ +package com.susu2568.base; + +public class demo03 { + static String salary = "2000"; + public static void main(String[] args) { + System.out.println(salary); + } +} +//类变量 \ No newline at end of file diff --git a/java/src/com/susu2568/exception/Demo01/Test.java b/java/src/com/susu2568/exception/Demo01/Test.java new file mode 100644 index 0000000..e4ab423 --- /dev/null +++ b/java/src/com/susu2568/exception/Demo01/Test.java @@ -0,0 +1,33 @@ +package com.susu2568.exception.Demo01; + +public class Test { + public static void main(String[] args) { + int a = 1; + int b = 0; +//若需要捕获多个异常 需从小到大 + try {//监控区域 + new Test().a(); + }catch (Throwable e){//捕获异常 + System.out.println("程序异常"); + }finally {//做善后工作 + System.out.println("finally"); + } + //快捷键 ctrl+alt+T + try { + + if (b==0) {//throw + throw new ArithmeticException();//抛出异常 + } else {System.out.println(a/b); + } + } catch (ArithmeticException e) { + e.printStackTrace();//打印错误的栈信息 + } finally { + } + } + public void a(){ + b(); + } + public void b(){ + a(); + } +} diff --git a/java/src/com/susu2568/exception/demo02/Test01.java b/java/src/com/susu2568/exception/demo02/Test01.java new file mode 100644 index 0000000..b2c1c96 --- /dev/null +++ b/java/src/com/susu2568/exception/demo02/Test01.java @@ -0,0 +1,18 @@ +package com.susu2568.exception.demo02; + +public class Test01 { + public void test(int a) throws Exception{ + if (a>10){ + throw new myException(); + } + System.out.println("ok"); + } + + public void main(String[] args) throws Exception { + try { + test(10); + } catch (myException e) { + System.out.println("myException=>"+e); + } + } +} diff --git a/java/src/com/susu2568/exception/demo02/myException.java b/java/src/com/susu2568/exception/demo02/myException.java new file mode 100644 index 0000000..7468738 --- /dev/null +++ b/java/src/com/susu2568/exception/demo02/myException.java @@ -0,0 +1,16 @@ +package com.susu2568.exception.demo02; + +public class myException extends Exception{ + private int detail; + + public void myException(int a){ + this.detail = a; + } + + @Override + public String toString() { + return "myException{" + + "detail=" + detail + + '}'; + } +} diff --git a/java/src/com/susu2568/method/Demo01.java b/java/src/com/susu2568/method/Demo01.java new file mode 100644 index 0000000..974ceea --- /dev/null +++ b/java/src/com/susu2568/method/Demo01.java @@ -0,0 +1,12 @@ +package com.susu2568.method; + +public class Demo01 { + public static void main(String[] args) { + Demo01 demo01 = new Demo01(); + demo01.test(); + + } + public void test(int... i){ + System.out.println(i); + } +} diff --git a/java/src/com/susu2568/method/Demo02.java b/java/src/com/susu2568/method/Demo02.java new file mode 100644 index 0000000..9baa926 --- /dev/null +++ b/java/src/com/susu2568/method/Demo02.java @@ -0,0 +1,31 @@ +package com.susu2568.method; + +public class Demo02 { + public static void main(String[] args) { + printMax(34, 3, 3, 2, 56.5); + printMax(new double[]{1, 2, 3}); + + } + + public static void printMax(double... numbers) { + if (numbers.length == 0) { + System.out.println("No argument passed"); + return; + } + double result = numbers[0]; + + for (int i = 0; i < numbers.length; i++) { + if (numbers[i] > result) { + result = numbers[i]; + } + } + System.out.println("The max value is " + result); + } +} + + +//out: +//The max value is 56.5 +// The max value is 3.0 + + diff --git a/java/src/com/susu2568/method/Demo03.java b/java/src/com/susu2568/method/Demo03.java new file mode 100644 index 0000000..508f31b --- /dev/null +++ b/java/src/com/susu2568/method/Demo03.java @@ -0,0 +1,14 @@ +package com.susu2568.method; + +public class Demo03 { + public static void main(String[] args) { + System.out.println(f(3)); + } + public static int f(int n){ + if (n==1){ + return 1; + }else { + return n*f(n-1); + } + } +} diff --git a/java/src/com/susu2568/oop/Application.java b/java/src/com/susu2568/oop/Application.java new file mode 100644 index 0000000..82be9b4 --- /dev/null +++ b/java/src/com/susu2568/oop/Application.java @@ -0,0 +1,22 @@ +package com.susu2568.oop; + +import com.susu2568.oop.Demo03.Person; +import com.susu2568.oop.Demo03.Worker; + +public class Application { + public static void main(String[] args) { + //一个方法的实际类型是确定的 + //可以指向的引用类型是不确定的 +// Worker s1 = new Worker(); +// Person s2 = new Worker(); + + Object object = new Worker(); + System.out.println(object instanceof Object); + System.out.println(object instanceof Person); + System.out.println(object instanceof Worker); + //instanceof---类型转换 + //System.out.println(X instanceof Y);--- X Y 是否存在父子关系 + //方法类型的转换----父----->子 直接转换 + // 父<-----子 强制转换 可能会丢失一些方法 + } +} diff --git a/java/src/com/susu2568/oop/Demo01/Application.java b/java/src/com/susu2568/oop/Demo01/Application.java new file mode 100644 index 0000000..8aaac70 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo01/Application.java @@ -0,0 +1,11 @@ +package com.susu2568.oop.Demo01; +//一个项目只有一个main方法 +public class Application { + public static void main(String[] args) { + Student student = new Student(); + student.name = "小明"; + student.age = 9; + student.age(); + student.study(); + } +} diff --git a/java/src/com/susu2568/oop/Demo01/Student.java b/java/src/com/susu2568/oop/Demo01/Student.java new file mode 100644 index 0000000..8154cb1 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo01/Student.java @@ -0,0 +1,14 @@ +package com.susu2568.oop.Demo01; +//学生类 +public class Student { + String name ; + int age ; + + public void study(){ + System.out.println(this.name+"在学习"); + } + + public void age() { + System.out.println("年龄:"+this.age+"岁"); + } +} diff --git a/java/src/com/susu2568/oop/Demo02/A.java b/java/src/com/susu2568/oop/Demo02/A.java new file mode 100644 index 0000000..59d6cb0 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo02/A.java @@ -0,0 +1,10 @@ +package com.susu2568.oop.Demo02; + +public class A extends B{ + + //重写----alt+ins + @Override//注解---有功能的注释 + public void test() { + System.out.println("A=>test()"); + } +} diff --git a/java/src/com/susu2568/oop/Demo02/B.java b/java/src/com/susu2568/oop/Demo02/B.java new file mode 100644 index 0000000..c40fc95 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo02/B.java @@ -0,0 +1,7 @@ +package com.susu2568.oop.Demo02; + +public class B { + public void test(){ + System.out.println("B=>test()"); + } +} diff --git a/java/src/com/susu2568/oop/Demo02/person.java b/java/src/com/susu2568/oop/Demo02/person.java new file mode 100644 index 0000000..0e0e843 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo02/person.java @@ -0,0 +1,21 @@ +package com.susu2568.oop.Demo02; + +public class person { + String name; + + public person() { + } + + public person(String name) { + this.name = name; + } + + + public void say(){ + System.out.println("说"); + } + + protected int age = 20; +} + +//alt + inscrlk 生成构造器 diff --git a/java/src/com/susu2568/oop/Demo02/teacher.java b/java/src/com/susu2568/oop/Demo02/teacher.java new file mode 100644 index 0000000..e9c3e98 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo02/teacher.java @@ -0,0 +1,21 @@ +package com.susu2568.oop.Demo02; + +public class teacher extends person{ + public static void main(String[] args) { + teacher teacher = new teacher(); + teacher.say(); + } + + private int age = 9; + public void test(int age){ + System.out.println(age); + System.out.println(this.age); + System.out.println(super.age); + } +} + + +// ctrl + H 显示继承关系 +// object 类 所有类默认继承 +//只有单继承------一个儿子只有一个爸爸 +// 一个爸爸可以有多个儿子 \ No newline at end of file diff --git a/java/src/com/susu2568/oop/Demo03/C.java b/java/src/com/susu2568/oop/Demo03/C.java new file mode 100644 index 0000000..7019082 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo03/C.java @@ -0,0 +1,5 @@ +package com.susu2568.oop.Demo03; + +public class C extends D{ + +} diff --git a/java/src/com/susu2568/oop/Demo03/D.java b/java/src/com/susu2568/oop/Demo03/D.java new file mode 100644 index 0000000..a3a3eda --- /dev/null +++ b/java/src/com/susu2568/oop/Demo03/D.java @@ -0,0 +1,6 @@ +package com.susu2568.oop.Demo03; +//abstract 抽象类 类: extends 只能单继承 接口可以多继承 +public abstract class D { + //不能new 抽象类 只能靠子类去实现 + //抽象类与抽象方法相对应 +} diff --git a/java/src/com/susu2568/oop/Demo03/Person.java b/java/src/com/susu2568/oop/Demo03/Person.java new file mode 100644 index 0000000..8c00066 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo03/Person.java @@ -0,0 +1,4 @@ +package com.susu2568.oop.Demo03; + +public class Person extends Object{ +} diff --git a/java/src/com/susu2568/oop/Demo03/Worker.java b/java/src/com/susu2568/oop/Demo03/Worker.java new file mode 100644 index 0000000..560be79 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo03/Worker.java @@ -0,0 +1,4 @@ +package com.susu2568.oop.Demo03; + +public class Worker extends Person{ +} diff --git a/java/src/com/susu2568/oop/Demo04/userService.java b/java/src/com/susu2568/oop/Demo04/userService.java new file mode 100644 index 0000000..ed6edf0 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo04/userService.java @@ -0,0 +1,9 @@ +package com.susu2568.oop.Demo04; +//接口 +//接口中所有定义为抽象的 +public interface userService { + void add(); + void delete(); + void update(); + void query(); +} diff --git a/java/src/com/susu2568/oop/Demo04/userServiceImpl.java b/java/src/com/susu2568/oop/Demo04/userServiceImpl.java new file mode 100644 index 0000000..660a2b2 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo04/userServiceImpl.java @@ -0,0 +1,23 @@ +package com.susu2568.oop.Demo04; + +public class userServiceImpl implements userService{ + @Override + public void add() { + + } + + @Override + public void delete() { + + } + + @Override + public void update() { + + } + + @Override + public void query() { + + } +} diff --git a/java/src/com/susu2568/oop/Demo05/Application.java b/java/src/com/susu2568/oop/Demo05/Application.java new file mode 100644 index 0000000..b951919 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo05/Application.java @@ -0,0 +1,10 @@ +package com.susu2568.oop.Demo05; + +public class Application { + public static void main(String[] args) { + Outer outer = new Outer(); + //通过外部类来实例化内部类 + Outer.Inter inter = outer.new Inter(); + inter.getId(); + } +} diff --git a/java/src/com/susu2568/oop/Demo05/Outer.java b/java/src/com/susu2568/oop/Demo05/Outer.java new file mode 100644 index 0000000..ce18c97 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo05/Outer.java @@ -0,0 +1,20 @@ +package com.susu2568.oop.Demo05; + +public class Outer { + private int id=20; + public void out(){ + System.out.println("这是一个外部类"); + } + + public class Inter{ + public void in(){ + System.out.println("这是一个内部类"); + } + + //获得外部类的私有属性 + public void getId(){ + System.out.println(id); + } + } + +} diff --git a/java/src/com/susu2568/oop/Demo05/Test.java b/java/src/com/susu2568/oop/Demo05/Test.java new file mode 100644 index 0000000..67f5391 --- /dev/null +++ b/java/src/com/susu2568/oop/Demo05/Test.java @@ -0,0 +1,22 @@ +package com.susu2568.oop.Demo05; +//匿名类 +public class Test { + public static void main(String[] args) { + new Apple().eat(); + new userService() { + @Override + public void hello() { + } + }; + } +} + +class Apple{ + public void eat(){ + System.out.println("1"); + } +} + +interface userService{ + void hello(); +} \ No newline at end of file diff --git a/java/src/com/susu2568/scanner/Demo01.java b/java/src/com/susu2568/scanner/Demo01.java new file mode 100644 index 0000000..59a75dc --- /dev/null +++ b/java/src/com/susu2568/scanner/Demo01.java @@ -0,0 +1,26 @@ +package com.susu2568.scanner; + + +import java.util.Scanner; + +public class Demo01 { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("使用next方法接收:"); + if(scanner.hasNextLine()){ + String str = scanner.nextLine(); + System.out.println("输出的内容为:"+str); + scanner.close(); + } + } +//out: +// 使用next方法接收: +// hello world +// 输出的内容为:hello world + + +} +//out : +// 使用next方法接收: +//hello wrold +//输出的内容为:hello \ No newline at end of file diff --git a/java/src/com/susu2568/test/Solution.java b/java/src/com/susu2568/test/Solution.java new file mode 100644 index 0000000..850c3dd --- /dev/null +++ b/java/src/com/susu2568/test/Solution.java @@ -0,0 +1,16 @@ +package com.susu2568.test; + +import java.util.Arrays; + +public class Solution { + public int arrayPairSum(int[] nums) { + Arrays.sort(nums); + int ans = 0; + for (int i = 0; i < nums.length; i += 2) { + ans += nums[i]; + } + return ans; + } + + +}