Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/yuyeongwoo/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2-4번 문제

정답 : a, b, c, d
3 changes: 3 additions & 0 deletions src/yuyeongwoo/report1/Report1_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2-7번 문제

정답 : 12, true, 131, 51, 99, Java, 오류
21 changes: 21 additions & 0 deletions src/yuyeongwoo/report1/Report1_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package yuyeongwoo.report1;
// 2-8 번 문제
public class Report1_3 {
public static void main(String[] args) {
int x = 1;
int y = 2;
int z = 3;

// 정답 작성
int a = x;
x = y;
y = z;
z = a;
//

System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println("z = " + z);
}
}

4 changes: 4 additions & 0 deletions src/yuyeongwoo/report2/Report2_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3-1번 문제

정답: d, e

30 changes: 30 additions & 0 deletions src/yuyeongwoo/report2/Report2_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package yuyeongwoo.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, 이유: true || false && false 가 되고, && 연산자의 우선순위가 더 높기 때문에 true || false 가 된다. 따라서 true가 나온다.
System.out.println(y += 10 - x++);
//결과: 13, 이유: 위 식을 풀어쓰게 되면, y = y + 10 - x++ 가 된다. x는 후위형이기 때문에 값이 증가하지 않은 상태에서 식이 계산된다. 따라서 y = 5 + 10 - 2 -> y = 13
System.out.println(x += 2);
//결과: 5, 이유: 이전 식에서 x의 값이 1증가했기 때문에 x = 3 + 2가 되어 x는 5가 된다.
System.out.println(!('A' <= c && c <= 'Z'));
//결과: false, 이유: c는 A와 Z사이에 존재하는 대문자이기 때문에 참이 된다. 하지만 논리부전연산자에 의해 false가 된다.
System.out.println('C' - c);
//결과: 2, 이유: 'C' 와 'A'는 정수로 변환되어 각 67, 65가 되고 따라서 67 - 65 = 2가 된다.
System.out.println('5' - '0');
//결과: 5, 이유: 위와 같은 이유로 53 - 48이 되어 5가 답이다.
System.out.println(c + 1);
//결과: 66, 'A'가 정수 65로 변환되고 65 + 1 = 66이 된다.
System.out.println(++c);
//결과: B, 이유: 'A'의 문자코드 값이 1증가되고, 66이 된다. 문자코드 66에 해당하는 문자 B를 출력한다.
System.out.println(c++);
//결과: B, 이유: 후위형이기 때문에 위에서 증가된 값 B가 출력되고 1증가한다.
System.out.println(c);
//결과: C, 이유: 위에서 1증가했기 때문에 문자코드 67에 해당하는 C가 출력된다.
}
}
9 changes: 9 additions & 0 deletions src/yuyeongwoo/report2/Report2_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package yuyeongwoo.report2;
// 3-3번 문제
public class Report2_3 {
public static void main(String[] args) {
int num = 456;
//정답
System.out.println(num / 100 * 100);
}
}
11 changes: 11 additions & 0 deletions src/yuyeongwoo/report2/Report2_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package yuyeongwoo.report2;
// 3-4번 문제
public class Report2_4 {
public static void main(String[] args) {
int numOfApples = 123;
int sizeOfBucket = 10;
//정답
int numOfbucket = numOfApples / sizeOfBucket + (numOfApples % 10 > 0 ? 1 : 0);
System.out.println("필요한 바구니의 수 : " + numOfbucket);
}
}
9 changes: 9 additions & 0 deletions src/yuyeongwoo/report2/Report2_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package yuyeongwoo.report2;
// 3-5번 문제
public class Report2_5 {
public static void main(String[] args) {
int num = 10;
//정답
System.out.println(num > 0 ? "양수" : num < 0 ? "음수" : "0");
}
}
12 changes: 12 additions & 0 deletions src/yuyeongwoo/report2/Report2_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package yuyeongwoo.report2;
// 3-6번 문제
public class Report2_6 {
public static void main(String[] args) {
int fahrenheit = 100;
//정답
float celcius = (int) (5 / 9f * (fahrenheit - 32) * 100 + 0.5) / 100f ;

System.out.println("fahrenheit = " + fahrenheit);
System.out.println("celcius = " + celcius);
}
}
26 changes: 26 additions & 0 deletions src/yuyeongwoo/report3/Report3_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
4-1번 문제

정답 :
//int형 변수 x가 10보다 크고 20보다 작을 때 true인 조건식
- 10 < x && x < 20

//char형 변수 ch가 공백이나 탭이 아닐 때 true인 조건식
- !(ch == ' ' || ch == \t)

//char형 변수 ch가 'x' 또는 'X'일 때 true인 조건식
- ch == 'x' || ch == 'X'

//char형 변수 ch가 숫자('0'~'9')일 때 true인 조건식
- '0' <= ch && ch <= '9'

//char형 변수 ch가 영문자(대문자 또는 소문자)일 때 true인 조건식
- ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')

//int형 변수 year가 400으로 나눠떨어지거나 또는 4로 나눠떨어지고 100으로 나눠떨어지지 않을때 true인 조건식
- year % 400 == 0 || year % 4 == 0 && year % 100 != 0

//boolean형 변수 powerOn이 false일 때 true인 조건식
- !powerOn

//문자열 참조변수 str이 "yes"일 때 true인 조건식
- str.equals("yes")
28 changes: 28 additions & 0 deletions src/yuyeongwoo/report3/Report3_10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package yuyeongwoo.report3;

import java.util.Scanner;

// 4-10번 문제
public class Report3_10 {
public static void main(String[] args) {
int answer = (int) (Math.random() * 100) + 1;
int input = 0;
int count = 0;

Scanner s = new Scanner(System.in);
do {
count++;
System.out.print("1과 100사이의 값을 입력하세요. : ");
input = s.nextInt();
if (answer > input) {
System.out.println("더 큰 수를 입력하세요.");
} else if (answer < input) {
System.out.println("더 작은 수를 입력하세요.");
} else {
System.out.println("맞혔습니다.");
System.out.println("시도횟수는 " + count + "번 입니다.");
break;
}
} while (true);
}
}
14 changes: 14 additions & 0 deletions src/yuyeongwoo/report3/Report3_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package yuyeongwoo.report3;
// 4-2번 문제
public class Report3_2 {
public static void main(String[] args) {
int sum = 0;
//정답
for (int i = 1; i < 20; i++) {
if (!(i % 2 == 0 || i % 3 == 0)) {
sum += i;
}
}
System.out.println("sum = " + sum);
}
}
14 changes: 14 additions & 0 deletions src/yuyeongwoo/report3/Report3_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package yuyeongwoo.report3;
// 4-3번 문제
public class Report3_3 {
public static void main(String[] args) {
int sum = 0;
int totalSum = 0;
//정답
for (int i = 1; i <= 10; i++) {
sum += i;
totalSum += sum;
}
System.out.println("totalSum = " + totalSum);
}
}
19 changes: 19 additions & 0 deletions src/yuyeongwoo/report3/Report3_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package yuyeongwoo.report3;
// 4-4번 문제
public class Report3_4 {
public static void main(String[] args) {
int sum = 0;
int s = 1;
int num = 0;
for (int i = 1; true; i++) {
sum += i * s;
if (sum >= 100) {
num = i * s;
break;
}
s = -s;
}
System.out.println("num = " + num);
System.out.println("sum = " + sum);
}
}
16 changes: 16 additions & 0 deletions src/yuyeongwoo/report3/Report3_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package yuyeongwoo.report3;
// 4-5번 문제
public class Report3_5 {
public static void main(String[] args) {
int i = 0;
while (i <= 10) {
int j = 0;
while (j <= i) {
System.out.print("*");
j++;
}
System.out.println();
i++;
}
}
}
13 changes: 13 additions & 0 deletions src/yuyeongwoo/report3/Report3_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package yuyeongwoo.report3;
// 4-6번 문제
public 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));
}
}
}
}
}
14 changes: 14 additions & 0 deletions src/yuyeongwoo/report3/Report3_7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package yuyeongwoo.report3;
// 4-7번 문제
public class Report3_7 {
public static void main(String[] args) {
String str = "12345";
int sum = 0;
//정답
for (int i = 0; i < str.length(); i++) {
// sum += Integer.parseInt(str.charAt(i) + "");
sum += str.charAt(i) - '0';
}
System.out.println("sum = " + sum);
}
}
8 changes: 8 additions & 0 deletions src/yuyeongwoo/report3/Report3_8.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package yuyeongwoo.report3;
// 4-8번 문제
public class Report3_8 {
public static void main(String[] args) {
int value = (int) (Math.random() * 6) + 1;
System.out.println("value = " + value);
}
}
13 changes: 13 additions & 0 deletions src/yuyeongwoo/report3/Report3_9.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package yuyeongwoo.report3;
// 4-9번 문제
public 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);
}
}
Binary file added src/yuyeongwoo/report3/Untitled Diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/yuyeongwoo/report4/Report4_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
5-1번 문제

정답 : 4번 - 이유: 배열의 개수에 따라 자동으로 크기가 지정되기 때문에 대괄호안에 숫자를 넣을 수 없다.
5번 - 이유: 배열을 선언하는 단계에서는 크기를 지정할 수 없다.
3 changes: 3 additions & 0 deletions src/yuyeongwoo/report4/Report4_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
5-2번 문제

정답 : 4번째 배열의 길이 - 2
12 changes: 12 additions & 0 deletions src/yuyeongwoo/report4/Report4_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package yuyeongwoo.report4;
// 5-3번 문제
public class Report4_3 {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
int sum = 0;
for (int i : arr) {
sum += i;
}
System.out.println("sum = " + sum);
}
}
23 changes: 23 additions & 0 deletions src/yuyeongwoo/report4/Report4_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package yuyeongwoo.report4;
// 5-4번 문제
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[0].length; j++) {
total += arr[i][j];
}
}
average = (float) total / (arr.length * arr[0].length);
System.out.println("total = " + total);
System.out.println("average = " + average);
}
}
30 changes: 30 additions & 0 deletions src/yuyeongwoo/report4/Report4_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package yuyeongwoo.report4;

import java.util.Arrays;

// 5-5번 문제
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];

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];
// }

ball3 = Arrays.copyOf(ballArr, 3);

for (int i = 0; i < ball3.length; i++) {
System.out.print(ball3[i]);
}
}
}
Loading