diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..7fb8ed0 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e1f0da4..a9c9ebd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -41,13 +41,6 @@ - - - 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/src/com/lyw/demo/HelloWorld.java b/src/com/lyw/demo/HelloWorld.java deleted file mode 100644 index 9391687..0000000 --- a/src/com/lyw/demo/HelloWorld.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.lyw.demo; - -/** - * Created by Administrator on 2016/11/22 0022. - */ -public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/src/com/lyw/jichuyufa/HelloWorld.java b/src/com/lyw/jichuyufa/HelloWorld.java new file mode 100644 index 0000000..9fc4ea6 --- /dev/null +++ b/src/com/lyw/jichuyufa/HelloWorld.java @@ -0,0 +1,14 @@ +package com.lyw.jichuyufa; + +/** + * Java语言第一类 + * + * @author Administrator + * @create 2016-11-30-上午 10:39 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello,World"); + } +} diff --git a/src/com/lyw/jichuyufa/OldSum.java b/src/com/lyw/jichuyufa/OldSum.java new file mode 100644 index 0000000..75ef034 --- /dev/null +++ b/src/com/lyw/jichuyufa/OldSum.java @@ -0,0 +1,27 @@ +package com.lyw.jichuyufa; + +/** + * 0~100之内奇数的和 + * + * @author Administrator + * @create 2016-11-30-下午 12:58 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class OldSum { + public static void main(String[] args) { + int result = 0; + + /*for (int i = 0; i < 100; i++) { + if (i % 2 != 0) + result += i; + }*/ + + for (int i = 1; i <= 99; i += 2) { + result += i; + } + + System.out.println("0~100之内奇数的和为:" + result); + + + } +} diff --git a/src/com/lyw/jichuyufa/TestBreakAndContinue.java b/src/com/lyw/jichuyufa/TestBreakAndContinue.java new file mode 100644 index 0000000..d17ccea --- /dev/null +++ b/src/com/lyw/jichuyufa/TestBreakAndContinue.java @@ -0,0 +1,25 @@ +package com.lyw.jichuyufa; + +/** + * break和continue + * + * @author Administrator + * @create 2016-11-30-下午 1:25 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestBreakAndContinue { + public static void main(String[] args) { + //break; + int stop = 4; + for (int i = 0; i < 10; i++) { + if (stop == i) break; + System.out.println(i); + } + + //continue + for (int i = 0; i < 5; i++) { + if (stop == i) continue; + System.out.println(i); + } + } +} diff --git a/src/com/lyw/jichuyufa/TestFor.java b/src/com/lyw/jichuyufa/TestFor.java new file mode 100644 index 0000000..ea81f12 --- /dev/null +++ b/src/com/lyw/jichuyufa/TestFor.java @@ -0,0 +1,20 @@ +package com.lyw.jichuyufa; + +/** + * for循环 + * + * @author Administrator + * @create 2016-11-30-下午 12:44 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestFor { + public static void main(String[] args) { + long result = 0; + long f = 1; + for (int i = 1; i <= 10; i++) { + f = f * i; + result += f; + } + System.out.println(result); + } +} diff --git a/src/com/lyw/jichuyufa/TestIf.java b/src/com/lyw/jichuyufa/TestIf.java new file mode 100644 index 0000000..a76919c --- /dev/null +++ b/src/com/lyw/jichuyufa/TestIf.java @@ -0,0 +1,23 @@ +package com.lyw.jichuyufa; + +/** + * 分支if + * + * @author Administrator + * @create 2016-11-30-下午 12:37 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestIf { + public static void main(String[] args) { + int i = 20; + if (i < 20) { + System.out.println("<20"); + } else if (i < 40) + System.out.println("<40"); + else if (i < 60) + System.out.println("<60"); + else + System.out.println(">60"); + System.out.println(">60"); + } +} diff --git a/src/com/lyw/jichuyufa/TestSwitch.java b/src/com/lyw/jichuyufa/TestSwitch.java new file mode 100644 index 0000000..94400f2 --- /dev/null +++ b/src/com/lyw/jichuyufa/TestSwitch.java @@ -0,0 +1,32 @@ +package com.lyw.jichuyufa; + +/** + * 分支Switch + * + * @author Administrator + * @create 2016-11-30-下午 1:45 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestSwitch { + public static void main(String[] args) { + int num = 2; + switch (num) { + case 1: + System.out.println("A"); + break; + case 2: + System.out.println("B"); + break; + case 3: + System.out.println("C"); + break; + case 4: + case 5: + System.out.println("D"); + break; + default: + System.out.println("error"); + break; + } + } +} diff --git a/src/com/lyw/jichuyufa/TestVar.java b/src/com/lyw/jichuyufa/TestVar.java new file mode 100644 index 0000000..88a6494 --- /dev/null +++ b/src/com/lyw/jichuyufa/TestVar.java @@ -0,0 +1,43 @@ +package com.lyw.jichuyufa; + +/** + * 变量作用域 + * + * @author Administrator + * @create 2016-11-30-上午 10:41 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestVar { + static int j; //成员变量 + + public static void main(String[] args) { + int i = 0; + System.out.println(i); + System.out.println(j); + + boolean b = false; + if (b) { + System.out.println("b is true"); + } + + long longNum1 = 8888888888888888888L; + } + + public void m() { + int i = 0; //局部变量 + int j = i + 5; + double d = 3.14; + Dog dog = new Dog(22, 7, 1964); + System.out.println(1); + } + + private class Dog { + int day, month, year; + + public Dog(int day, int month, int year) { + this.day = day; + this.month = month; + this.year = year; + } + } +} diff --git a/src/com/lyw/jichuyufa/TestVar2.java b/src/com/lyw/jichuyufa/TestVar2.java new file mode 100644 index 0000000..4e95aac --- /dev/null +++ b/src/com/lyw/jichuyufa/TestVar2.java @@ -0,0 +1,20 @@ +package com.lyw.jichuyufa; + +/** + * 数据类型练习 + * + * @author Administrator + * @create 2016-11-30-上午 11:55 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestVar2 { + public static void main(String[] args) { + boolean b = true; + char x, y = 9; + x = 'a'; + double num = 3.1415926; + System.out.println(String.format("b={0}", b)); + System.out.println("x=" + x + ",y=" + y); + System.out.println("num=" + num); + } +} diff --git a/src/com/lyw/jichuyufa/TestWhileAndDoWhile.java b/src/com/lyw/jichuyufa/TestWhileAndDoWhile.java new file mode 100644 index 0000000..91fe86b --- /dev/null +++ b/src/com/lyw/jichuyufa/TestWhileAndDoWhile.java @@ -0,0 +1,24 @@ +package com.lyw.jichuyufa; + +/** + * while和do...while循环 + * + * @author Administrator + * @create 2016-11-30-下午 1:10 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestWhileAndDoWhile { + public static void main(String[] args) { + int i = 0; + while ((i < 10)) { + System.out.println(i); + i++; + } + + i = 0; + do { + System.out.println(i); + i++; + } while (i < 10); + } +} diff --git a/src/com/lyw/jichuyufa/TestXunHuan.java b/src/com/lyw/jichuyufa/TestXunHuan.java new file mode 100644 index 0000000..ee5910c --- /dev/null +++ b/src/com/lyw/jichuyufa/TestXunHuan.java @@ -0,0 +1,40 @@ +package com.lyw.jichuyufa; + +/** + * 循环测试 + * + * @author Administrator + * @create 2016-11-30-下午 1:30 + * 物勒工名,以考其诚,工有不当,必行其罪,以究其情 + */ +public class TestXunHuan { + public static void main(String[] args) { + //输出1~100之内前5个可以被3整除的数字 + int num = 0; + for (int i = 1; i <= 100; i++) { + if (i % 3 == 0) { + System.out.print(i + "\t"); + num++; + } + + if (num == 5) break; + } + + System.out.println(); + + //输出101~200内的质数,质数只能被1和本身整除 + for (int i = 101; i <= 200; i++) { + boolean flag = true; + for (int j = 2; j < i; j++) { + if (i % j == 0) { + flag = false; + break; + } + } + if (flag) { + System.out.print(i + "\t"); + } + } + + } +} diff --git a/src/com/lyw/suanfa/InsertionSort.java b/src/com/lyw/suanfa/InsertionSort.java new file mode 100644 index 0000000..04c44e5 --- /dev/null +++ b/src/com/lyw/suanfa/InsertionSort.java @@ -0,0 +1,27 @@ +package com.lyw.suanfa; + +/** + * Created by Administrator on 2016/11/24 0024. + * 插入排序 + */ +public class InsertionSort { + public static void main(String[] args) { + int[] array = {1, -5, 3, 78, 5, 0}; + insertionSort(array); + for (int i : array) { + System.out.print(i + "\t"); + } + } + + private static void insertionSort(int[] arr) { + for (int i = 1; i < arr.length; i++) { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = key; + } + } +}