diff --git a/src/josungjae/report1/Report1_1 b/src/josungjae/report1/Report1_1 new file mode 100644 index 0000000..a4f9f98 --- /dev/null +++ b/src/josungjae/report1/Report1_1 @@ -0,0 +1,3 @@ +2-4번 문제 + +정답 : float f = 3.14 diff --git a/src/josungjae/report1/Report1_2 b/src/josungjae/report1/Report1_2 new file mode 100644 index 0000000..a2577fc --- /dev/null +++ b/src/josungjae/report1/Report1_2 @@ -0,0 +1,3 @@ +2-7번 문제 + +정답 : 12, true, 131, 51, 99, Java, 오류 \ No newline at end of file diff --git a/src/josungjae/report1/Report1_3.java b/src/josungjae/report1/Report1_3.java new file mode 100644 index 0000000..06636e3 --- /dev/null +++ b/src/josungjae/report1/Report1_3.java @@ -0,0 +1,18 @@ +package josungjae.report1; +// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수 +public class Report1_3{ + public static void main(String[] args){ + int x = 1; + int y = 2; + int z = 3; + + z = x; + x = y; + y = y + z; + + System.out.println("x="+x); + System.out.println("y="+y); + System.out.println("z="+z); + + } +} \ No newline at end of file diff --git a/src/josungjae/report2/Report2_1 b/src/josungjae/report2/Report2_1 new file mode 100644 index 0000000..1161169 --- /dev/null +++ b/src/josungjae/report2/Report2_1 @@ -0,0 +1,3 @@ +3-1번 문제 + +정답 : b = (byte)i;, ch = (char)b;, float f = (float)l;, i = (int)ch; \ No newline at end of file diff --git a/src/josungjae/report2/Report2_2.java b/src/josungjae/report2/Report2_2.java new file mode 100644 index 0000000..dd7c421 --- /dev/null +++ b/src/josungjae/report2/Report2_2.java @@ -0,0 +1,30 @@ +package josungjae.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보다는 큰것은 참인데, x는 0보다 크므로 거짓 " || " 연산자는 하나만 참이면 참이 나오므로 true + System.out.println(y += 10 - x++); +// 13 : y는 5에 += 에 따라 5+10을 하여 15를 한 뒤 -x (=2)에 따라 13이 된다. + System.out.println(x += 2); +// 3 : 이전 식에서 x++에 의해 1이 증가되었고, 거기에 2를 더하여 답이 3이 되었다. + System.out.println(!('A' <= c && c <= 'Z')); +// false : 'A' <=c = true 이고 c<='Z' = false 이므로 false + System.out.println('C' - c); +// 2 : 65 - 63 = 2 + System.out.println('5' - '0'); +// 5 : 5-0 = 5 + System.out.println(c + 1); +// 66 = 65+1 = 66 + System.out.println(++c); +// B = 증감연산자 독립 사용으로 값 변환 없음 + System.out.println(c++); +// B = 증감연산자 독립 사용으로 값 변환 없음 + System.out.println(c); +// c = 이전 과정에 의해 67이되어 '67' = 대문자 C + } +} diff --git a/src/josungjae/report2/Report2_3.java b/src/josungjae/report2/Report2_3.java new file mode 100644 index 0000000..c24ccc6 --- /dev/null +++ b/src/josungjae/report2/Report2_3.java @@ -0,0 +1,8 @@ +package josungjae.report2; +// 3-3번 문제 +public class Report2_3 { + public static void main(String[] args) { + int num = 456; + System.out.println(Math.floor(num * 0.01) * 100); + } +} diff --git a/src/josungjae/report2/Report2_4.java b/src/josungjae/report2/Report2_4.java new file mode 100644 index 0000000..e16b079 --- /dev/null +++ b/src/josungjae/report2/Report2_4.java @@ -0,0 +1,11 @@ +package josungjae.report2; +// 3-4번 문제 +public class Report2_4 { + public static void main(String[] args) { + int numOfApples = 123; // 사과의 개수 + int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수) + int numOfBucket = (numOfApples / sizeOfBucket + 1); // 모든 사과를 담는데 필요한 바구니의 수 + + System.out.println("필요한 바구니의 수 :" + numOfBucket); + } +} diff --git a/src/josungjae/report2/Report2_5.java b/src/josungjae/report2/Report2_5.java new file mode 100644 index 0000000..92f6335 --- /dev/null +++ b/src/josungjae/report2/Report2_5.java @@ -0,0 +1,8 @@ +package josungjae.report2; +//3-5번 문제 +public class Report2_5 { + public static void main(String[] args) { + int num = 10; + System.out.println(num > 0 ? "양수" : -num*-num > 0 ? "음수":"0"); + } +} diff --git a/src/josungjae/report3/Report3_1.java b/src/josungjae/report3/Report3_1.java new file mode 100644 index 0000000..176bffa --- /dev/null +++ b/src/josungjae/report3/Report3_1.java @@ -0,0 +1,61 @@ +//package josungjae.report3; +// +//public class Report3_1 { +//// 4-1번 문제 +// +////int형 변수 x가 10보다 크고 20보다 작을 때 true인 조건식 +// int x; +// +// if (x > 10 && x < 20) {} +// +// +////char형 변수 ch가 공백이나 탭이 아닐 때 true인 조건식 +// +// char ch; +// +// if ( ch != ' ' || ch != '') {} +// +////char형 변수 ch가 'x' 또는 'X'일 때 true인 조건식 +// +// char ch; +// +// if (ch == 'x' || ch == 'X') {} +// +////char형 변수 ch가 숫자('0'~'9')일 때 true인 조건식 +// +// char ch; +// +// if (ch >= '0' && ch <= '9') {} +// +////char형 변수 ch가 영문자(대문자 또는 소문자)일 때 true인 조건식 +// +// char ch +// +// if (ch >= 'a' && ch <= 'z') { +// if (ch >= 'A' && ch <= 'Z'){ +// +// } +// } +// +////int형 변수 year가 400으로 나눠떨어지거나 또는 4로 나눠떨어지고 100으로 나눠떨어지지 않을때 true인 조건식 +// +// int year +// +// if (year % 400 == 0 || year % 4 == 0) { +// if ( year % 100 != 0) {} +// } +// +////boolean형 변수 powerOn이 false일 때 true인 조건식 +// +// boolean powerON; +// +// if (powerOn == false) {} +// +////문자열 참조변수 str이 "yes"일 때 true인 조건식 +// +// String str; +// if (str.equals("yes")) { +// +// } +// +//} diff --git a/src/josungjae/report3/Report3_10.java b/src/josungjae/report3/Report3_10.java new file mode 100644 index 0000000..b20db65 --- /dev/null +++ b/src/josungjae/report3/Report3_10.java @@ -0,0 +1,29 @@ +package josungjae.report3; +//4-10 문제 +class Report3_10 { + public static void main(String[] args) { + // 1~100사이의 임의의 값을 얻어서 answer에 저장한다. + int answer = (int)(Math.random() * 100) +1; + 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 (answer > input) { + System.out.println("더 큰수를 입력하세요."); + } else if (answer < input) { + System.out.println("더 작은 수를 입력하세요."); + } else { + System.out.println("맞췄습니다."); + System.out.println("시도횟수는" + count + "번입니다."); + break; + } + + } while(true); //무한반복문 + } // end of main +} //end of class diff --git a/src/josungjae/report3/Report3_2.java b/src/josungjae/report3/Report3_2.java new file mode 100644 index 0000000..74315c7 --- /dev/null +++ b/src/josungjae/report3/Report3_2.java @@ -0,0 +1,10 @@ +package josungjae.report3; +//4-2번 문제 +class Report3_2 { + public static void main(String[] args) { + int sum = 0; + if (sum % 2 != 0 || sum % 3 != 0) + + System.out.println("sum="+sum); + } +} diff --git a/src/josungjae/report3/Report3_3.java b/src/josungjae/report3/Report3_3.java new file mode 100644 index 0000000..337bf31 --- /dev/null +++ b/src/josungjae/report3/Report3_3.java @@ -0,0 +1,15 @@ +package josungjae.report3; +//4-3번 문제 + +class Report3_3 { + public static void main(String[] args) { + int sum = 0; + int totalSum = 0; + + for (int i = 0; i <= 10; i++) { + sum += i; + } + + System.out.println("totalSum="+totalSum); + } +} diff --git a/src/josungjae/report3/Report3_4.java b/src/josungjae/report3/Report3_4.java new file mode 100644 index 0000000..0f88dfd --- /dev/null +++ b/src/josungjae/report3/Report3_4.java @@ -0,0 +1,20 @@ +package josungjae.report3; +//4-4번 문제 +class Report3_4 { + public static void main(String[] args) { + int sum = 0; // 총합을 저장할 변수 + int s = 1; // 값의 부호를 바꿔주는데 사용할 변수 + int num = 0; + + for (int i = 1; true; i++, s = -s) { + num = s * i; + sum += num; + + if (sum >= 100) + break; + } + + System.out.println("num="+num); + System.out.println("sum="+sum); + } +} diff --git a/src/josungjae/report3/Report3_5.java b/src/josungjae/report3/Report3_5.java new file mode 100644 index 0000000..f3e521b --- /dev/null +++ b/src/josungjae/report3/Report3_5.java @@ -0,0 +1,18 @@ +package josungjae.report3; +//4_5번 문제 +class Report3_5 { + public static void main(String[] args) { +// for(int i=0; i<=10; i++) { +// for(int j=0; j<=i; j++) + + int i = 0; + while (i <= 10) { + int j = 0; + while (j <= i) { + System.out.print("*"); + j++; + } System.out.println(); + i++; + } + }//end of main +} // end of class diff --git a/src/josungjae/report3/Report3_6.java b/src/josungjae/report3/Report3_6.java new file mode 100644 index 0000000..16be6ab --- /dev/null +++ b/src/josungjae/report3/Report3_6.java @@ -0,0 +1,10 @@ +package josungjae.report3; +//4-6번 문제 +class Report3_6 { + public static void main(String[] args) { + for (int i = 1; i <= 6; i++) + for (int j = 1; j <= 6; j++) + if (i + j == 6) + System.out.println(i + " + " + j + " = " + (i + j)); + } +} diff --git a/src/josungjae/report3/Report3_7.java b/src/josungjae/report3/Report3_7.java new file mode 100644 index 0000000..c725e5b --- /dev/null +++ b/src/josungjae/report3/Report3_7.java @@ -0,0 +1,14 @@ +package josungjae.report3; +//4-7번 문제 +class Report3_7 { + public static void main(String[] args) { + String str = "12345"; + int sum = 0; + + for (int i = 0; i < str.length(); i++) { + sum += str.charAt(i) - '0'; + } + + System.out.println("sum=" + sum); + } +} diff --git a/src/josungjae/report3/Report3_8.java b/src/josungjae/report3/Report3_8.java new file mode 100644 index 0000000..76af131 --- /dev/null +++ b/src/josungjae/report3/Report3_8.java @@ -0,0 +1,8 @@ +package josungjae.report3; +//4-8 문제 +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/josungjae/report3/Report3_9.java b/src/josungjae/report3/Report3_9.java new file mode 100644 index 0000000..ae3ce0f --- /dev/null +++ b/src/josungjae/report3/Report3_9.java @@ -0,0 +1,15 @@ +package josungjae.report3; +//4-9번 문제 +class Report3_9 { + public static void main(String[] args) { + int num = 12345; + int sum = 0; + + while (num > 0) { + sum += num%10; // 10으로 나누고 + num /= 10; // 10으로 나머지 연산 + } + + System.out.println("sum="+sum); + } +} //예상결과 : sum=15 diff --git "a/src/josungjae/report3/\353\241\234\352\267\270\354\235\270\355\235\220\353\246\204.png" "b/src/josungjae/report3/\353\241\234\352\267\270\354\235\270\355\235\220\353\246\204.png" new file mode 100644 index 0000000..012d1e6 Binary files /dev/null and "b/src/josungjae/report3/\353\241\234\352\267\270\354\235\270\355\235\220\353\246\204.png" differ diff --git a/src/josungjae/report4/Report4_2.java b/src/josungjae/report4/Report4_2.java new file mode 100644 index 0000000..284d99c --- /dev/null +++ b/src/josungjae/report4/Report4_2.java @@ -0,0 +1,12 @@ +package josungjae.report4; + +class Report4_2 { + + int[][]arr ={ + {5,5,5,5,5}, + {10,10,10}, + {20,20,20,20}, + {30,30} + }; + +} // arr[3].length = 2 {30, 30} diff --git a/src/josungjae/report4/Report4_3.java b/src/josungjae/report4/Report4_3.java new file mode 100644 index 0000000..80ec3d1 --- /dev/null +++ b/src/josungjae/report4/Report4_3.java @@ -0,0 +1,14 @@ +package josungjae.report4; +// 5-3번 문제 +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); + } +} //예상 결과 : sum = 150 diff --git a/src/josungjae/report4/Report4_4.java b/src/josungjae/report4/Report4_4.java new file mode 100644 index 0000000..a6bc21c --- /dev/null +++ b/src/josungjae/report4/Report4_4.java @@ -0,0 +1,27 @@ +package josungjae.report4; +//5-4번 문제 + +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/josungjae/report4/Report4_5.java b/src/josungjae/report4/Report4_5.java new file mode 100644 index 0000000..63b354d --- /dev/null +++ b/src/josungjae/report4/Report4_5.java @@ -0,0 +1,33 @@ +package josungjae.report4; + +//5-5번 문제 + +import java.util.Arrays; + +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/josungjae/report4/Report4_6.java b/src/josungjae/report4/Report4_6.java new file mode 100644 index 0000000..96197ac --- /dev/null +++ b/src/josungjae/report4/Report4_6.java @@ -0,0 +1,34 @@ +package josungjae.report4; + +//5-6번 문제 + +import java.util.Scanner; + +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[]로 변환 + + for (int j = 0; j < question.length; j++) { + int k = (int) (Math.random() * question.length); + + char tmp = question[j]; + question[j] = question[k]; + question[k] = 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/josungjae/report4/Rrport4_1 b/src/josungjae/report4/Rrport4_1 new file mode 100644 index 0000000..85e9568 --- /dev/null +++ b/src/josungjae/report4/Rrport4_1 @@ -0,0 +1,11 @@ +int[] arr[]; + +int[] arr = {1,2,3,}; + +int[] arr = new int[5]; + +int[] arr = new int[5]{1,2,3,4,5}; // - new int[5]에서 두 번쨰 대괄호 []에 숫자를 넣으면 안됨. + +int arr[5]; // - 배열을 선언할 떄는 배열의 크기를 지정할 수 없음. + +int[] arr[] = new int[3][]; diff --git a/src/studentenglishname/report1/Report1_3.java b/src/studentenglishname/report1/Report1_3.java deleted file mode 100644 index 5b75b9c..0000000 --- a/src/studentenglishname/report1/Report1_3.java +++ /dev/null @@ -1,17 +0,0 @@ -package studentenglishname.report1; -// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수 -public class Report1_3 { - public static void main(String[] args) { - // 정답 작성 - // Ex) - AddClass addClass = new AddClass(); - addClass.test(); - } -} - -// 필요하다면 클래스 추가 -class AddClass { - void test() { - System.out.println("AddClass.test"); - } -} 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) { - - } -}