diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.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 diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a818314 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7160440 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/2\354\243\274\354\260\250 \355\201\264\353\241\240.iml" "b/2\354\243\274\354\260\250 \355\201\264\353\241\240.iml" new file mode 100644 index 0000000..52575f3 --- /dev/null +++ "b/2\354\243\274\354\260\250 \355\201\264\353\241\240.iml" @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/studentenglishname/report1/Report1_1 b/src/studentenglishname/report1/Report1_1 deleted file mode 100644 index 3f37658..0000000 --- a/src/studentenglishname/report1/Report1_1 +++ /dev/null @@ -1,3 +0,0 @@ -2-4번 문제 - -정답 : diff --git a/src/studentenglishname/report1/Report1_2 b/src/studentenglishname/report1/Report1_2 deleted file mode 100644 index f4e5811..0000000 --- a/src/studentenglishname/report1/Report1_2 +++ /dev/null @@ -1,3 +0,0 @@ -2-7번 번 문제 - -정답 : \ No newline at end of file diff --git a/src/studentenglishname/report2/Report2_2.java b/src/studentenglishname/report2/Report2_2.java deleted file mode 100644 index 71dbb48..0000000 --- a/src/studentenglishname/report2/Report2_2.java +++ /dev/null @@ -1,7 +0,0 @@ -package studentenglishname.report2; -// 3-2번 문제 -public class Report2_2 { - public static void main(String[] args) { - - } -} diff --git a/src/wooramhong/report1/Report1_1 b/src/wooramhong/report1/Report1_1 new file mode 100644 index 0000000..069150f --- /dev/null +++ b/src/wooramhong/report1/Report1_1 @@ -0,0 +1,6 @@ +2-4번 문제 + +정답 :byte b = 256; //byte는 -128~127까지임으로 (byte)256이여야함 + char c = ''; //공백문자의 부재 + char answer = 'no'; // char는 영단어 하나만 + float f = 3.14 //함수는 뒤에 f가 붙어야함 diff --git a/src/wooramhong/report1/Report1_2 b/src/wooramhong/report1/Report1_2 new file mode 100644 index 0000000..45e9ced --- /dev/null +++ b/src/wooramhong/report1/Report1_2 @@ -0,0 +1,9 @@ +2-7번 번 문제 + +정답 : System.out.println("1" + "2"); // 12 + System.out.println(true + ""); //true + System.out.println('A' + 'B'); //131 + System.out.println('1' + 2); //51 + System.out.println('1' + '2'); //99 + System.out.println('J' + "ava"); //Java + System.out.println(true + null); //오류 \ No newline at end of file diff --git a/src/studentenglishname/report1/Report1_3.java b/src/wooramhong/report1/Report1_3.java similarity index 67% rename from src/studentenglishname/report1/Report1_3.java rename to src/wooramhong/report1/Report1_3.java index 5b75b9c..27478da 100644 --- a/src/studentenglishname/report1/Report1_3.java +++ b/src/wooramhong/report1/Report1_3.java @@ -1,8 +1,17 @@ -package studentenglishname.report1; +package wooramhong.report1; // 2-8 번 문제 <- 이렇게 문제 번호 작성 필수 public class Report1_3 { public static void main(String[] args) { - // 정답 작성 + int x = 1; + int y = 2; + int z = 3; + int temp=0; + + temp=x; + x=y; + y=z; + z=temp; + // Ex) AddClass addClass = new AddClass(); addClass.test(); diff --git a/src/wooramhong/report2/Report2_1 b/src/wooramhong/report2/Report2_1 new file mode 100644 index 0000000..4a6aa73 --- /dev/null +++ b/src/wooramhong/report2/Report2_1 @@ -0,0 +1,5 @@ +3-1번문제 + +정답 :1. b=(byte)i + 2. float f = (float)l; + 3. i = (int)ch \ No newline at end of file diff --git a/src/wooramhong/report2/Report2_2.java b/src/wooramhong/report2/Report2_2.java new file mode 100644 index 0000000..ba65d05 --- /dev/null +++ b/src/wooramhong/report2/Report2_2.java @@ -0,0 +1,22 @@ +package wooramhong.report2; +// 3-2번 문제 +public class Report2_2 { + public static void main(String[] args) { + int x = 2; + int y = 5; + char c = 'A'; // 'A'의 문자코드는 65 + + System.out.println(y >= 5 || x < 0 && x > 2); //True y>=5가 성립하기 때문에 + System.out.println(y += 10 - x++); //13 x++은 뒤에 적용되기 때문에 + System.out.println(x += 2); //5 x = x+2와 같은 의미기 때문에 + System.out.println(!('A' <= c && c <= 'Z')); //false &&으로 두가지가 모두 성립하지 않으면 false + System.out.println('C' - c); //2 C의 문자코드가 67 + System.out.println('5' - '0'); //5 int형으로 변환 + System.out.println(c + 1); //66 c='A'이고 A의 문자코드는 65 고로 65+1 + System.out.println(++c); //B c='A'이고 A의 문자코드는 65 거기에 +1을 해 66인 상태로 다시 char로 변환하면 B + System.out.println(c++); //B 위에서 B가 되었고, 늦게 더해짐으로 + System.out.println(c); //C 위에서 늦게나마 +1이 되어서 + + } +} + diff --git a/src/wooramhong/report2/Report2_3 b/src/wooramhong/report2/Report2_3 new file mode 100644 index 0000000..ac54f12 --- /dev/null +++ b/src/wooramhong/report2/Report2_3 @@ -0,0 +1,3 @@ +3-3번 문제 + +정답: (num/100)*100 \ No newline at end of file diff --git a/src/wooramhong/report2/Report2_4.java b/src/wooramhong/report2/Report2_4.java new file mode 100644 index 0000000..e941057 --- /dev/null +++ b/src/wooramhong/report2/Report2_4.java @@ -0,0 +1,11 @@ +package wooramhong.report2; +//3-4번문제 +public class Report2_4 { + public static void main(String[] args) { + int numOfApples = 123; // 사과의 개수 + int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수) + int numOfBucket = numOfApples % sizeOfBucket > 0 ? numOfApples/sizeOfBucket+1 : numOfApples%sizeOfBucket ;// 모든 사과를 담는데 필요한 바구니의 수 + + System.out.println("필요한 바구니의 수 :"+numOfBucket); + } +} diff --git a/src/wooramhong/report2/Report2_5 b/src/wooramhong/report2/Report2_5 new file mode 100644 index 0000000..3a92e8d --- /dev/null +++ b/src/wooramhong/report2/Report2_5 @@ -0,0 +1,3 @@ +3-5번 문제 + +정답:num == 0 ? 0 : num>0? "양수입니다.":"음수입니다" \ No newline at end of file diff --git a/src/wooramhong/report2/Report2_6.java b/src/wooramhong/report2/Report2_6.java new file mode 100644 index 0000000..4db766d --- /dev/null +++ b/src/wooramhong/report2/Report2_6.java @@ -0,0 +1,11 @@ +package wooramhong.report2; + +public class Report2_6 { + public static void main(String[] args) { + int fahrenheit = 100; + double celcius = Math.floor(((float)5/9 *(fahrenheit-32))*100) > ((float)5/9 *(fahrenheit-32))*100 -0.5? Math.floor(((float)5/9 *(fahrenheit-32))*100)/100 : Math.floor(((float)5/9 *(fahrenheit-32))*100)/100+0.01; + + System.out.println("Fahrenheit:"+fahrenheit); + System.out.println("Celcius:"+celcius); + } +} diff --git a/src/wooramhong/report3/Report3_1.java b/src/wooramhong/report3/Report3_1.java new file mode 100644 index 0000000..ed70005 --- /dev/null +++ b/src/wooramhong/report3/Report3_1.java @@ -0,0 +1,61 @@ +package wooramhong.report3; + +import java.util.Scanner; + +class Report3_1 { + public static void main(String[] args) { + Scanner scanner=new Scanner(System.in); + int x=scanner.nextInt(); + if (x>10&&20>x) { + System.out.println(true); + } + } + public static void main2(String[] args) { + char ch= 'A'; + if (ch != ' ' || ch !='\t') { + System.out.println(true); + } + } + + public static void main3(String[] args) { + char ch= 'A'; + if (ch == 'x' || ch == 'X') { + System.out.println(true); + } + } + + public static void main4(String[] args) { + char ch= 'A'; + if (ch >= '0' && ch <= '9') { + System.out.println(true); + } + } + + public static void main5(String[] args) { + char ch= 'A'; + if (ch >= 'a' && ch <='z' || ch >= 'A' && ch<='Z') { + System.out.println(true); + } + } + + public static void main6(String[] args) { + int year=5; + if (year % 4== 0 || year % 100 != 0) { + System.out.println(true); + } + } + + public static void main7(String[] args) { + boolean powerOn = false; + if (powerOn = false) { + System.out.println(true); + } + } + + public static void main8(String[] args) { + String str = "yes"; + if (str == "yes") { + System.out.println(true); + } + } +} diff --git a/src/wooramhong/report3/Report3_10.java b/src/wooramhong/report3/Report3_10.java new file mode 100644 index 0000000..27f2475 --- /dev/null +++ b/src/wooramhong/report3/Report3_10.java @@ -0,0 +1,30 @@ +package wooramhong.report3; + +public class Report3_10 { + public static void main(String[] args) { + // 1~100사이의 임의의 값을 얻어서 answer에 저장한다. + int answer = (int)(Math.random()*101); + int input = 0; //사용자입력을 저장할 공간 + int count = 0; //시도횟수를 세기위한 변수 + + // 화면으로 부터 사용자입력을 받기 위해서 Scanner클래스 사용 + java.util.Scanner s = new java.util.Scanner(System.in); + do { + count++; + System.out.print("1과 100사이의 값을 입력하세요 : "); + input = s.nextInt(); //입력받은 값을 변수 input에 저장한다. + if (input == answer) { + System.out.println("정답입니다."+count+"번째에 맞추셨습니다."); + break; + } else if (input>100) { + System.out.println("100 이하의 숫자를 입력하세요"); + } else if (input<0) { + System.out.println("1 이상의 숫자를 입력하세요"); + }else if (inputanswer) { + System.out.println("더 낮은 숫자입니다."); + } + } while(true); //무한반복문 + } // end of main +} diff --git a/src/wooramhong/report3/Report3_2.java b/src/wooramhong/report3/Report3_2.java new file mode 100644 index 0000000..17e31bd --- /dev/null +++ b/src/wooramhong/report3/Report3_2.java @@ -0,0 +1,11 @@ +package wooramhong.report3; + +class Report3_2 { + public static void main(String[] args) { + int sum = 0; + for (int i = 0; i < 21; i++) { + sum+=i; + } + System.out.println("sum="+sum); + } +} diff --git a/src/wooramhong/report3/Report3_3.java b/src/wooramhong/report3/Report3_3.java new file mode 100644 index 0000000..68d3c5c --- /dev/null +++ b/src/wooramhong/report3/Report3_3.java @@ -0,0 +1,15 @@ +package wooramhong.report3; + +class Report3_3 { + public static void main(String[] args) { + int sum = 0; + int totalSum = 0; + for (int i = 0; i < 11; i++) { + for (int j = 0; j < i; j++) { + sum+=j; + } + totalSum+=sum; + } + System.out.println("totalSum="+totalSum); + } +} diff --git a/src/wooramhong/report3/Report3_4.java b/src/wooramhong/report3/Report3_4.java new file mode 100644 index 0000000..cd2529c --- /dev/null +++ b/src/wooramhong/report3/Report3_4.java @@ -0,0 +1,21 @@ +package wooramhong.report3; + +class Report3_4 { + public static void main(String[] args) { + int sum = 0; // 총합을 저장할 변수 + int s = 1; // 값의 부호를 바꿔주는데 사용할 변수 + int num = 0; + while(sum<100){ + if (s % 2==0) { + sum-=s; + } + else { + sum+=s; + } + s++; + } + num=s; + System.out.println("num="+num); + System.out.println("sum="+sum); + } +} diff --git a/src/wooramhong/report3/Report3_5.java b/src/wooramhong/report3/Report3_5.java new file mode 100644 index 0000000..157b4e1 --- /dev/null +++ b/src/wooramhong/report3/Report3_5.java @@ -0,0 +1,22 @@ +package wooramhong.report3; + +class Report3_5 { + public static void main(String[] args) { +// for (int i = 0; i <= 10; i++) { +// for (int j = 0; j <= i; j++) +// System.out.print("*"); +// System.out.println(); +// } + int i=0; + int j=0; + while(i<=10){ + i++; + j=0; + while(j<=i){ + j++; + System.out.print("*"); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/src/wooramhong/report3/Report3_6.java b/src/wooramhong/report3/Report3_6.java new file mode 100644 index 0000000..b67c7b9 --- /dev/null +++ b/src/wooramhong/report3/Report3_6.java @@ -0,0 +1,17 @@ +package wooramhong.report3; + +class Report3_6 { + public static void main(String[] args) { + int[] dice1={1,2,3,4,5,6}; + int[] dice2={1,2,3,4,5,6}; + + for (int i = 0; i < dice1.length; i++) { + for (int j = 0; j < dice2.length; j++) { + int sum=dice1[i]+dice2[j]; + if (sum==6) { + System.out.println("첫번쨰 주사위"+dice1[i]+"와 두번째 주사위"+dice2[j]); + } + } + } + } +} diff --git a/src/wooramhong/report3/Report3_7.java b/src/wooramhong/report3/Report3_7.java new file mode 100644 index 0000000..9daefb3 --- /dev/null +++ b/src/wooramhong/report3/Report3_7.java @@ -0,0 +1,15 @@ +package wooramhong.report3; + +class Report3_7 { + public static void main(String[] args) { + String str = "12345"; + int sum = 0; + + for (int i = 0; i < str.length(); i++) { + char[] chArr = str.toCharArray(); + sum+=(int)chArr[i]-48; + } + + System.out.println("sum=" + sum); + } +} diff --git a/src/wooramhong/report3/Report3_8.java b/src/wooramhong/report3/Report3_8.java new file mode 100644 index 0000000..65ad930 --- /dev/null +++ b/src/wooramhong/report3/Report3_8.java @@ -0,0 +1,8 @@ +package wooramhong.report3; + +public class Report3_8 { + public static void main(String[] args){ + int value = (int)(Math.random()*6+1); + System.out.println("value:"+value); + } +} diff --git a/src/wooramhong/report3/Report3_9.java b/src/wooramhong/report3/Report3_9.java new file mode 100644 index 0000000..d95b9dc --- /dev/null +++ b/src/wooramhong/report3/Report3_9.java @@ -0,0 +1,13 @@ +package wooramhong.report3; + +class Report3_9 { + public static void main(String[] args) { + int num = 12345; + int sum = 0; + while(num>0){ + sum += num%10; + num/=10; + } + System.out.println("sum="+sum); + } +} diff --git "a/src/wooramhong/report3/\353\241\234\352\267\270\354\235\270flow.drawio" "b/src/wooramhong/report3/\353\241\234\352\267\270\354\235\270flow.drawio" new file mode 100644 index 0000000..a52f054 --- /dev/null +++ "b/src/wooramhong/report3/\353\241\234\352\267\270\354\235\270flow.drawio" @@ -0,0 +1 @@ +1Zhbb5swFMc/jR9bYczFfgSabZo0aVMm7dkNbkAiISLk0n76Hd+4hrZpm6XrS83Bxz6cc35/ExBJVsevFd9kP8pUFMh10iMid8iFvwDDP2l51JaQBdqwrPJUm3BrmOdPwhgdY93lqdj2JtZlWdT5pm9clOu1WNQ9G6+q8tCf9lAW/V03fClGhvmCF2PrnzytM22lbtjav4l8mdmdccD0nRW3k82TbDOeloeOicwQSaqyrPVodUxEIZNn86L9vkzcbQKrxLp+jQP57u8O96vi19Oc70Mc7n57qxtXr7Lnxc48sAm2frQZEOs0komEq0XBt9t8gUic1asCDBiGVblbp0Ju4sCVdhfpKKttmLaMvFqK+pnYSJMk6C5RrkRdPYLfoS2Db1KbdSpgbZUoeJ3v+2Fw0w3LZrlmh59lDgG6julcn9362sc0LnP6S2zLXbUQxqub9pcWwuFgJZ2I0Uow6Dx3a1JlPaPEZFziWYRiF1EHzRIUBYjdyQGNEUvkgM0Qw6M2OGR5LeYbvpDXB4C93wV8u9H4PeRH2QymEfaiqsXx+VYYl9g6jFJHTOo6PUBP9AB1psvdS++5ufRO5DKR+Ys9NItRxBDzrAV2CAoIKL6vYLSUIzknZoiqybGjKhCrUlA0u0OMopie8lI1ob7awkGRPypOy6CsxQulek9lTCFO1AG7JwoRXKoQ/ifWreC6utUjpjlHz5et/jpDpC4sWsFJ0CIsqZHqhRVxgAwQ51viptiZwJNEsINajaDYN0jCyo2LqwQS1tfAgkBKTtV8wBDueopf4FHCrsYUy3Ezx5BLzZr0rZoAob4jTmpVXYcboCixPjo1IP5Ehj4tK85lZcU43OB+0/mvlBk87PIP05nwE+sMvarO0MHZTPy3Ks1wJY/8W62hr9KaLmwAUSiB0rBFVlzau1i9SoFvKOlt5alhW4kXjZRYaGnQvlrRlBEsEnJt8T4Bm8MyOdd+CWDXgvNa0DXpbV7DPFuUc6lrXgyml7owdjaA57kzyATqSFPc0cROw+3PFjONGbKmIOqRaE89SSJR8y255izXaHe3iGRszO2cnrT9DXVtQl2nX1I39K8MKMYvE7rN+EYOHwpxNKjG51FrHw9j7Wo+IoW3Af0PmHbDYdXctzI9lIcg/DCk4bL9UqWnt9/7yOwv \ No newline at end of file diff --git a/src/wooramhong/report4/Report4_1.java b/src/wooramhong/report4/Report4_1.java new file mode 100644 index 0000000..da7fae8 --- /dev/null +++ b/src/wooramhong/report4/Report4_1.java @@ -0,0 +1,12 @@ +package wooramhong.report4; + +class Report4_1 { +// public static void main(String[] args) { +// int[] arr[]; //안됨 배열에 대한 선언이 없음 +// int[] arr = {1,2,3,}; +// int[] arr = new int[5]; +// int[] arr = new int[5]{1,2,3,4,5}; //안됨 길이를 선언했을 경우 따로 배열에 값을 넣어줘야함 +// int arr[5]; //안됨 형식이 잘못됌 +// int[] arr[] = new int[3][]; +// } +} diff --git a/src/wooramhong/report4/Report4_2.java b/src/wooramhong/report4/Report4_2.java new file mode 100644 index 0000000..be6f637 --- /dev/null +++ b/src/wooramhong/report4/Report4_2.java @@ -0,0 +1,12 @@ +package wooramhong.report4; + +class Report4_2 {//2 + public static void main(String[] args) { + int[][]arr ={ + {5,5,5,5,5}, + {10,10,10}, + {20,20,20,20}, + {30,30} + }; + } +} diff --git a/src/wooramhong/report4/Report4_3.java b/src/wooramhong/report4/Report4_3.java new file mode 100644 index 0000000..634f889 --- /dev/null +++ b/src/wooramhong/report4/Report4_3.java @@ -0,0 +1,12 @@ +package wooramhong.report4; + +class Report4_3 { + public static void main(String[] args) { + int[] arr = {10, 20, 30, 40, 50}; + int sum = 0; + for (int i = 0; i < arr.length; i++) { + sum+=arr[i]; + } + System.out.println("sum="+sum); + } +} diff --git a/src/wooramhong/report4/Report4_4.java b/src/wooramhong/report4/Report4_4.java new file mode 100644 index 0000000..61b0168 --- /dev/null +++ b/src/wooramhong/report4/Report4_4.java @@ -0,0 +1,25 @@ +package wooramhong.report4; + +public class Report4_4 { + public static void main(String[] args) { + int[][] arr = { + { 5, 5, 5, 5, 5 }, + { 10, 10, 10, 10, 10 }, + { 20, 20, 20, 20, 20 }, + { 30, 30, 30, 30, 30 } + }; + + int total = 0; + float average = 0; + + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr[i].length; j++) { + total+=arr[i][j]; + } + } + average = total/ (float)(arr.length*arr[0].length); + + System.out.println("total=" + total); + System.out.println("average=" + average); + } // end of main +} diff --git a/src/wooramhong/report4/Report4_5.java b/src/wooramhong/report4/Report4_5.java new file mode 100644 index 0000000..db64f2c --- /dev/null +++ b/src/wooramhong/report4/Report4_5.java @@ -0,0 +1,30 @@ +package wooramhong.report4; + +import java.util.Arrays; + +public class Report4_5 { + public static void main(String[] args) { + int[] ballArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int[] ball3 = new int[3]; + + // 배열 ballArr의 임의의 요소를 골라서 위치를 바꾼다 + for (int i = 0; i < ballArr.length; i++) { + int j = (int) (Math.random() * ballArr.length); + int tmp = 0; + tmp = ballArr[i]; + ballArr[i] = ballArr[j]; + ballArr[j] = tmp; + } + + for (int i = 0; i < 3; i++) { + ball3[i] = ballArr[i]; + } + + // 배열 ballArr의 앞에서 3개의 수를 배열 ball3로 복사한다 + ball3 = Arrays.copyOf(ballArr, 3); + + for (int i = 0; i < ball3.length; i++) { + System.out.print(ball3[i]); + } + }//end of main +} diff --git a/src/wooramhong/report4/Report4_6.java b/src/wooramhong/report4/Report4_6.java new file mode 100644 index 0000000..4d5e4a5 --- /dev/null +++ b/src/wooramhong/report4/Report4_6.java @@ -0,0 +1,31 @@ +package wooramhong.report4; + +import java.util.Scanner; + +public class Report4_6 { + public static void main(String[] args) { + String[] words = {"television", "computer", "mouse", "phone"}; + + Scanner scanner = new Scanner(System.in); + + for (int i = 0; i < words.length; i++) { + char[] question = words[i].toCharArray(); // String을 char[]로 변환 + + int j = (int)(Math.random()*words.length); + int tmp = 0; + + tmp = question[i]; + question[i] = question[j]; + question[j] = (char) tmp; + + System.out.printf("Q%d. %s의 정답을 입력하세요 .>", i + 1, new String(question)); + String answer = scanner.nextLine(); + + // trim()으로 answer의 좌우 공백을 제거한 후, equals로 word[i]와 비교 + if (words[i].equals(answer.trim())) { + System.out.printf("맞았습니다.%n%n"); + }else{ + System.out.printf("틀렸습니다.%n%n");} + } + } +} diff --git a/src/wooramhong/report5/Report5_1.java b/src/wooramhong/report5/Report5_1.java new file mode 100644 index 0000000..437c94e --- /dev/null +++ b/src/wooramhong/report5/Report5_1.java @@ -0,0 +1,89 @@ +package wooramhong.report5; + + +//5-2 +class Report5_2 { + public static void main(String[] args) { + Student s = new Student("홍길동", 1, 1, 100, 60, 76); + + String str = s.info(); + System.out.println(str); + } +} +//5-3 +class Exercise6_4 { + public static void main(String args[]) { + Student s = new Student(); + s.name = "홍길동"; + s.ban = 1; + s.no = 1; + s.kor = 100; + s.eng = 60; + s.math = 76; + System.out.println("이름 :"+s.name); + System.out.println("총점 :"+s.getTotal()); + System.out.println("평균 :"+s.getAverage()); + }//예상 결과 : 이름 : 홍길동, 총점 : 236, 평균 : 78.7 +} +//5-1 +class Student{ + String name; + int ban; + int no; + int kor; + int eng; + int math; + static int total; + static float aver; + Student(){} + Student(String name, int ban, int no,int kor,int eng, int math) { + this.name = name; + this.ban = ban; + this.no = no; + this.kor = kor; + this.eng = eng; + this.math = math; + } + int getTotal(){ + return kor+eng+math; + } + float getAverage(){ + return (float)getTotal()/3; + } + String info(){ + return name + "," + ban + "," + no + "," + kor + "," + eng + "," + math; + } +} + + +//5-4 +class PlayingCard { + int kind; //인스턴스 변수 + int num; //인스턴스 변수 + static int width; //클래스 변수 + static int height; //클래스 변수 + PlayingCard(int k, int n) { + kind = k; //전역변수 + num = n; //전역변수 + } + public static void main(String args[]) { + PlayingCard card = new PlayingCard(1,1); + } +} +//5-5 +class Marine { + int x=0, y=0; //Marine의 위치좌표 (x,y) + int hp = 60; //현재 체력 + static int weapon = 6; //공격력 - 모든 마린들의 공격력은 같아야 하기 때문 + static int armor = 0; //방어력 - 모든 마린들의 방어력은 같아야 하기 때문 + void weaponUp() { + weapon++; + } + void armorUp() { + armor++; + } + void move(int x, int y) { + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/src/wooramhong/report6/Report6 b/src/wooramhong/report6/Report6 new file mode 100644 index 0000000..6f8f7c4 --- /dev/null +++ b/src/wooramhong/report6/Report6 @@ -0,0 +1,35 @@ +6-1번문제 + +정답 : b-생성자는 객체를 초기화시키기 위한 것,e-오버로딩 가능하다. + +6-2번 문제 + +정답: d-사용할 수 있다 + +6-3번 문제 + +정답: d-변수의 이름이 꼭 다를 필요는 없다. + +6-4번 문제 + +정답: b,d + +6-5번 문제 + +정답: e-클래스 변수는 클래스 로딩시 초기화, 인스턴스 변수는 인스턴스 생성때마다 초기화 + +6-6번 문제 + +정답: b + +6-7번 문제 + +정답: e-힙 영역에서는 주로 긴 생명주기를 가진 데이터들이 생성된다 + +6-8번 문제 + +정답: b-종료된 상태가 아닌, 위의 메소드가 끝날때까지 대기상태다. + +6-9번 문제 + +정답: ABC123456- 문자열 \ No newline at end of file diff --git a/src/wooramhong/report7/Report7.java b/src/wooramhong/report7/Report7.java new file mode 100644 index 0000000..3df18ff --- /dev/null +++ b/src/wooramhong/report7/Report7.java @@ -0,0 +1,155 @@ +package wooramhong.report7; + +//7-1 +//class Exercise6_17 { +// +// public static int[] shuffle(int[] arr) { +// +// for(int i = 0; i < arr.length; i++) { +// int j = (int)(Math.random()*arr.length); +// +// // arr[i]와 arr[j]의 값을 서로 바꾼다. +// int tmp = arr[i]; +// arr[i] = arr[j]; +// arr[j] = tmp; +// } +// return arr; +// } +// +// public static void main(String[] args) { +// int[] original = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; +// System.out.println(java.util.Arrays.toString(original)); +// +// int[] result = shuffle(original); +// System.out.println(java.util.Arrays.toString(result)); +// } +//} + +//7-2 +//class Exercise6_18 { +// public static boolean isNumber(String str){ +// char[] a= str.toCharArray(); +// for (int i = 0; i < a.length; i++) { +// int b=a[i]-48; +// if(!(b<=9 && 0<=b)){ +// return false; +// } +// }return true; +// +// } +// +// public static void main(String[] args) { +// String str = "123"; +// System.out.println(str + " 는 숫자입니까? " + isNumber(str)); +// str = "1234o"; +// System.out.println(str + " 는 숫자입니까? " + isNumber(str)); +// } +//} + +//7-3번 +//class MyTv { +// boolean isPowerOn; +// int channel; +// int volume; +// final int MAX_VOLUME = 100; +// final int MIN_VOLUME = 0; +// final int MAX_CHANNEL = 100; +// final int MIN_CHANNEL = 1; +// void turnOnOff() { +// isPowerOn = !isPowerOn; +// if (isPowerOn){ +// return; +// } +// // (1) isPowerOn의 값이 true면 false로, false면 true로 바꾼다. +// } +// void volumeUp() { +// if (volumeMIN_VOLUME){ +// volume--; +// } +// // (3) volume의 값이 MIN_VOLUME보다 클 때만 값을 1 감소시킨다. +// } +// void channelUp() { +// if (channelMIN_CHANNEL){ +// channel--; +// } else if (channel==MIN_CHANNEL) { +// channel=MAX_CHANNEL; +// } +// // (5) channel의 값을 1 감소시킨다 . +// // 만일 channel이 MIN_CHANNEL이면, channel의 값을 MAX_CHANNEL로 바꾼다. +// } +//} +// +//class Exercise6_19 { +// public static void main(String args[]) { +// MyTv t = new MyTv(); +// t.channel = 100; +// t.volume = 0; +// System.out.println("CH:" + t.channel + ", VOL:" + t.volume); +// t.channelDown(); +// t.volumeDown(); +// System.out.println("CH:" + t.channel + ", VOL:" + t.volume); +// t.volume = 100; +// t.channelUp(); +// t.volumeUp(); +// System.out.println("CH:" + t.channel + ", VOL:" + t.volume); +// } +//} + + +//7-4번 +//class Exercise6_20 { +// static int big=0; +// public static int max(int[] arr){ +// if((arr == new int[]{})||(arr==null)){ +// big = -9999; +// }else{ +// for (int i = 0; i < arr.length ; i++) { +// if (arr[i] > big) { +// big = arr[i]; +// } +// } +// } +// +// return big; +// } +// public static void main(String[] args) { +// int[] data = {3,2,9,4,7}; +// System.out.println(java.util.Arrays.toString(data)); +// System.out.println("최대값 :"+max(data)); +// System.out.println("최대값 :"+max(null)); +// System.out.println("최대값 :"+max(new int[]{})); // 크기가 0인 배열 } +// } +//} + +//7-5번 +class Exercise6_21 { + public static int abs(int value){ + if(value>=0){ + return value; + }else{ + return -value; + } + } + public static void main(String[] args) { + int value = 5; + System.out.println(value + "의 절대값 :" + abs(value)); + value = -10; + System.out.println(value + "의 절대값 :" + abs(value)); + } +} +//예상 결과 : 5의 절대값 : 5 / -10의 절대값 : 10 \ No newline at end of file diff --git a/src/wooramhong/report8/Report8.java b/src/wooramhong/report8/Report8.java new file mode 100644 index 0000000..c505ab9 --- /dev/null +++ b/src/wooramhong/report8/Report8.java @@ -0,0 +1,170 @@ +package wooramhong.report8; + +class SutdaDeck { + final int CARD_NUM = 20; + SutdaCard[] cards = new SutdaCard[CARD_NUM]; + + SutdaDeck() { + for (int i = 0; i < CARD_NUM; i++) { + cards[i]=new SutdaCard(); + cards[i].num = i%10+1; + cards[i].isKwang=(i<10) && ((i==0) || (i==2) || (i==7))? true:false; + } + } + void shuffle() { + for (int i = 0; i < cards.length; i++) { + int j= (int)(Math.random()* cards.length); + int tem = 0; + + tem = cards[i].num; + cards[i].num=cards[j].num; + cards[j].num=tem; + } + } + + SutdaCard pick(int index) { + return cards[index]; + } + SutdaCard pick() { + int random =(int)(Math.random()*cards.length); + return cards[random]; + } +} + +class SutdaCard { + int num; + boolean isKwang; + + SutdaCard() { + this(1, true); + } + + SutdaCard(int num, boolean isKwang) { + this.num = num; + this.isKwang = isKwang; + } + + // info()대신 Object클래스의 toString()을 오버라이딩했다. + public String toString() { + return num + ( isKwang ? "K":""); + } +} +//8-1 +//class Exercise7_1 { +// public static void main(String args[]) { +// SutdaDeck deck = new SutdaDeck(); +// +// for (int i = 0; i < deck.cards.length; i++) +// System.out.print(deck.cards[i] + ","); +// } +//} + +//8-2 +// class Exercise7_2 { +// public static void main(String args[]) { +// SutdaDeck deck = new SutdaDeck(); +// +// System.out.println(deck.pick(0)); +// System.out.println(deck.pick()); +// deck.shuffle(); +// +// for(int i=0; i < deck.cards.length;i++) +// System.out.print(deck.cards[i]+","); +// +// System.out.println(); +// System.out.println(deck.pick(0)); +// } +// } + + +//8-3 +//class Product { +// int price; // 제품의 가격 +// int bonusPoint; // 제품구매 시 제공하는 보너스점수 +// +// Product(){} +// +// Product(int price) { +// this.price = price; +// bonusPoint = (int) (price / 10.0); +// } +//} +// +//class Tv extends Product { +// Tv() { +// } +// +// public String toString() { +// return "Tv"; +// } +//} +// +//class Exercise7_3 { +// public static void main(String[] args) { +// Tv t = new Tv(); +// } +//} + +//8-4 +class MyTv { + private boolean isPowerOn; + private int channel; + private int volume; + private int prevChannel; + private int prevChannel2; + + final int MAX_VOLUME = 100; + final int MIN_VOLUME = 0; + final int MAX_CHANNEL = 100; + final int MIN_CHANNEL = 1; + + int getChannel(){ + return channel; + } + int getVolume(){ + return volume; + } + void setChannel(int num){ + prevChannel=channel; + if(num>=MIN_CHANNEL && MAX_CHANNEL>num){ + channel=num; + } + } + void setVolume(int num){ + if(num>=MIN_VOLUME && MAX_VOLUME>num){ + volume=num; + } + } + void gotoPrevChannel(){ + prevChannel2=channel; + channel=prevChannel; + prevChannel=prevChannel2; + } +} + +//8-4 +//class Exercise7_4 { +// public static void main(String args[]) { +// MyTv t = new MyTv(); +// +// t.setChannel(10); +// System.out.println("CH:" + t.getChannel()); +// t.setVolume(20); +// System.out.println("VOL:" + t.getVolume()); +// } +//} + +//8-5 +//class Exercise7_5 { +// public static void main(String args[]) { +// MyTv t = new MyTv(); +// t.setChannel(10); +// System.out.println("CH:" + t.getChannel()); +// t.setChannel(20); +// System.out.println("CH:" + t.getChannel()); +// t.gotoPrevChannel(); +// System.out.println("CH:" + t.getChannel()); +// t.gotoPrevChannel(); +// System.out.println("CH:" + t.getChannel()); +// } +//} diff --git a/untitled/.idea/.gitignore b/untitled/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/untitled/.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 diff --git a/untitled/.idea/misc.xml b/untitled/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/untitled/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/untitled/.idea/modules.xml b/untitled/.idea/modules.xml new file mode 100644 index 0000000..3007dae --- /dev/null +++ b/untitled/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/untitled/.idea/quest01.java b/untitled/.idea/quest01.java new file mode 100644 index 0000000..a96d748 --- /dev/null +++ b/untitled/.idea/quest01.java @@ -0,0 +1,57 @@ +//public class quest01 { +// public static void main(String[] args) { +////2-4. 다음 중 변수를 잘못 초기화 한 것은? + //byte b = 256; //byte는 -128~127까지임으로 (byte)256이여야함 + //char c = ''; //공백문자의 부재 + //char answer = 'no'; // char는 영단어 하나만 + //float f = 3.14 //함수는 뒤에 f가 붙어야함 + //double d = 1.4e3f; +// } +//} + +//public class quest02 { +// public static void main(String[] args) { +////2-7. 다음 문장들의 출력 결과를 적으세요. 오류가 있는 문장의 경우, '오류' 라고 적으세요. +//// System.out.println("1" + "2"); // 12 +// System.out.println(true + ""); //true +// System.out.println('A' + 'B'); //131 +// System.out.println('1' + 2); //51 +// System.out.println('1' + '2'); //99 +// System.out.println('J' + "ava"); //Java +// //System.out.println(true + null); //오류 +// } +//} + +//2-8. 아래는 변수 x, y, z의 값을 서로 바꾸는 예제이다. 결과와 같이 출력되도록 코드를 넣으세요. +//public class quest03{ +// public static void main(String[] args){ +// int x = 1; +// int y = 2; +// int z = 3; +// int temp=0; +// +// temp=x; +// x=y; +// y=z; +// z=temp; +// +// System.out.println("x="+x); +// System.out.println("y="+y); +// System.out.println("z="+z); +// } +//} +//예상 결과 : x=2, y=3, z=1 +//public class Quest { +// public static void main(String[] args) { +// byte b = 10; +// char ch = 'A'; +// int i = 100; +// long l = 1000L; +////3-1. 다음 중 형변환을 생략할 수 있는 것은? (모두 고르시오) +// b = (byte) i; //생략 가능 +// ch = (char) b; +// short s = (short) ch; +// float f = (float) l; +// i = (int) ch; +// } +//} \ No newline at end of file diff --git a/untitled/.idea/vcs.xml b/untitled/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/untitled/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/untitled/Hello.java b/untitled/Hello.java new file mode 100644 index 0000000..926cf53 --- /dev/null +++ b/untitled/Hello.java @@ -0,0 +1,14 @@ +public class Hello { + public static void main(String[] args) { + byte b = 10; + char ch = 'A'; + int i = 100; + long l = 1000L; +//3-1. 다음 중 형변환을 생략할 수 있는 것은? (모두 고르시오) + b = (byte) i; //생략 가능 + ch = (char) b; + short s = (short) ch; + float f = (float) l; + i = (int) ch; + } +} diff --git a/untitled/untitled.iml b/untitled/untitled.iml new file mode 100644 index 0000000..8b2ade9 --- /dev/null +++ b/untitled/untitled.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file