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
9 changes: 7 additions & 2 deletions src/choiwonbin/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2-4번 문제
//2-4. 다음 중 변수를 잘못 초기화 한 것은?
byte b = 256;
char c = '';
char answer = 'no';
float f = 3.14;
double d = 1.4e3f;

정답 :
정답 : b, c, answer, f
17 changes: 15 additions & 2 deletions src/choiwonbin/report1/Report1_2
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2-7번 번 문제
//2-7. 다음 문장들의 출력 결과를 적으세요. 오류가 있는 문장의 경우, '오류' 라고 적으세요.
System.out.println("1" + "2");
System.out.println(true+"");
System.out.println('A' + 'B');
System.out.println('1' + 2);
System.out.println('1' + '2');
System.out.println('J' +"ava");
System.out.println(true + null);

정답 :
정답 : 12
true
131
51
99
Java
오류
34 changes: 21 additions & 13 deletions src/choiwonbin/report1/Report1_3.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package choiwonbin.report1;
// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수
public class Report1_3 {
public static void main(String[] args) {
// 정답 작성
// Ex)
AddClass addClass = new AddClass();
addClass.test();
}
}
//2-8. 아래는 변수 x, y, z의 값을 서로 바꾸는 예제이다. 결과와 같이 출력되도록 코드를 넣으세요.
//예상 결과 : x=2, y=3, z=1

class Exercise2_8 {
public static void main(String[] args){

// 필요하다면 클래스 추가
class AddClass {
void test() {
System.out.println("AddClass.test");
int x = 1;
int y = 2;
int z = 3;
/*
알맞은 코드를 넣어 완성하세요.
*/
int temp = x;
x = y;
y = z;
z = temp;

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

}

14 changes: 14 additions & 0 deletions src/choiwonbin/report2/Report2_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//3-1. 다음 중 형변환을 생략할 수 있는 것은? (모두 고르시오)

byte b = 10;
char ch = 'A';
int i = 100;
long l = 1000L;

b = (byte)i;
ch = (char)b;
short s = (short)ch;
float f = (float)l;
i = (int)ch;

정답 : i = (int)ch;
31 changes: 31 additions & 0 deletions src/choiwonbin/report2/Report2_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//3-2. 다음 연산의 결과와 그 이유를 적으세요.
class Exercise3_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);
System.out.println(y += 10 - x++);
System.out.println(x += 2);
System.out.println(!('A' <= c && c <= 'Z'));
System.out.println('C' - c);
System.out.println('5' - '0');
System.out.println(c + 1);
System.out.println(++c);
System.out.println(c++);
System.out.println(c);
}
}

정답 : 1. true / 비교연산자는 &&가 ||보다 우위이고 y > 5가 참이므로 || 연산자에 의해 참입니다.
2. 13 / value++는 참조 이후에 처리되기 때문에 y += 10 - 2 => y = 5 + 10 - 2 => y = 13
3. 4 / x는 수식에서 사용되어서 증감연산이 작용하지 않아서 x = 2이고 2 + 2 = 4
4. false / 'A' <= c = true, c <= 'Z' = true 둘다 모두 참이기에 ('A' <= c && c <= 'Z')는 참이고 이것의 부정은 false
5. 2 / 'C'의 문자코드는 67이고 변수 c 즉 'A'의 문자코드는 65이므로 67 - 65 = 2
6. 5 / '5'는 5 '0'은 0이므로 5-0 = 5
7. 66 / 'A' 의 코드는 65이고 65+1=66
8. 'B' / ++c는 증가 후 대입
9. 'B' / c는 이전에 'B'가 되었고 c++는 대입후 출력
10. 'C' / 이전에 증가되었기에 'C'

7 changes: 0 additions & 7 deletions src/choiwonbin/report2/Report2_2.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/choiwonbin/report2/Report2_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package choiwonbin.report2;
//3-3. 아래는 변수의 num 값 중에서 백의 자리 이하를 버리는 코드이다.
//만일 변수 num의 값이 '456'이라면 '400'이 되고, '111'이라면 '100'이 된다.
//알맞은 코드를 넣으시오.
class Exercise3_3 {
public static void main(String[] args){
int num = 456;
System.out.println(num/100*100);
}
}
16 changes: 16 additions & 0 deletions src/choiwonbin/report2/Report2_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package choiwonbin.report2;

//3-4. 아래의 코드는 사과를 담는데 필요한 바구니(버켓)의 수를 구하는 코드이다.
//만일 사과의 수가 123개이고 하나의 바구니에는 10개의 사과를 담을 수 있다면, 13개의 바구니가 필요할 것이다.
//알맞은 코드를 넣으시오.

//예상 결과 -> 필요한 바구니의 수 :13
class Exercise3_4 {
public static void main(String[] args){
int numOfApples = 123; // 사과의 개수
int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수)
int numOfBucket = (numOfApples/sizeOfBucket + ((numOfApples%sizeOfBucket) > 0 ? 1 : 0)); // 모든 사과를 담는데 필요한 바구니의 수

System.out.println("필요한 바구니의 수 :"+numOfBucket);
}
}
12 changes: 12 additions & 0 deletions src/choiwonbin/report2/Report2_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package choiwonbin.report2;

//3-5. 아래는 변수 num의 값에 따라 '양수', '음수', '0'을 출력하는 코드이다.
//삼항연산자를 이용해서 빈칸에 알맞은 코드를 넣으시오.
//Hint : 삼항 연산자를 두 번 사용할 것!
class Exercise3_5{
public static void main(String[] args){
int num = 10;
System.out.println(num == 0 ? 0 : (num > 0 ? "양수" : "음수"));
}
}
//예상 결과 : 양수
16 changes: 16 additions & 0 deletions src/choiwonbin/report2/Report2_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package choiwonbin.report2;

//3-6. 아래는 화씨(Fahrenheit)를 섭씨(Celcius)로 변환하는 코드이다.
//변환 공식이 'C = 5/9*(F-32)'라고 할 때, 빈 칸에 알맞은 코드를 넣으시오.
// 단, 변환값은 소수점 셋째자리에서 반올림하며, Math.round() 함수를 사용하지 않고 처리할 것!

//예상 결과 : Fahrenheit:100, Celcius:37.78
class Exercise3_6 {
public static void main(String[] args){
int fahrenheit = 100;
float celcius = (int)((5f/9f*(fahrenheit-32))*100 + 0.5f)/100f;

System.out.println("Fahrenheit:"+fahrenheit);
System.out.println("Celcius:"+celcius);
}
}
26 changes: 24 additions & 2 deletions src/choiwonbin/report3/Report3_1
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
// 4-1번 문제
//4-1. 다음의 문장들을 조건식으로 표현해보세요.

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

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

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

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

//char형 변수 ch가 영문자(대문자 또는 소문자)일 때 true인 조건식
(ch > 'a' && ch < 'z') || (ch > 'A' && 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")
16 changes: 16 additions & 0 deletions src/choiwonbin/report3/Report3_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package choiwonbin.report3;

//4-2. 1부터 20까지의 정수중에서 2 또는 3의 배수가 아닌 수의 총합을 구하세요.
class Exercise4_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);
}
}
19 changes: 19 additions & 0 deletions src/choiwonbin/report3/Report3_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package choiwonbin.report3;

//4-3. 1+(1+2)+(1+2+3)+(1+2+3+4)+...+(1+2+3+...+10)의 결과를 계산하세요.
class Exercise4_3 {
public static void main(String[] args) {
int sum = 0;
int totalSum = 0;

for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= i; j++) {
sum += j;
}
System.out.println();
totalSum += sum;
sum = 0;
}
System.out.println("totalSum="+totalSum);
}
}
20 changes: 20 additions & 0 deletions src/choiwonbin/report3/Report3_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package choiwonbin.report3;

//4-4. 1+(-2)+3+(-4)+...과 같은 식으로 계속 더해나갔을 때,
//몇까지 더해야 총합이 100 이상이 되는지 구하세요.
class Exercise4_4 {
public static void main(String[] args) {
int sum = 0; // 총합을 저장할 변수
int s = 1; // 값의 부호를 바꿔주는데 사용할 변수
int num = 0;

for (int i = 1; sum < 100; i++) {
num = i * s;
sum += num;
s = -s;
}

System.out.println("num="+num);
System.out.println("sum="+sum);
}
}
26 changes: 26 additions & 0 deletions src/choiwonbin/report3/Report3_5
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//4-5. 다음의 for문을 while문으로 변경하세요.
public class Exercise4_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();
}
}//end of main
} // end of class

public class Exercise4_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++;
}
}//end of main
} // end of class
15 changes: 15 additions & 0 deletions src/choiwonbin/report3/Report3_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package choiwonbin.report3;

//4-6. 두 개의 주사위를 던졌을 때, 눈의 합이 6이 되는 모든 경우의 수를 출력하는 프로그램을 작성하세요.
class Exercise4_6 {
public static void main(String[] args) {
for (int i = 0; i < 6; i ++) {
for (int j = 0; j < 6; j ++) {
if (i + j == 6) {
System.out.printf("%d + %d = %d", i, j, i + j);
System.out.println();
}
}
}
}
}
8 changes: 8 additions & 0 deletions src/kwonseongmin/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//2-4. 다음 중 변수를 잘못 초기화 한 것은?
byte b = 256;
char c = '';
char answer = 'no';
float f = 3.14;
double d = 1.4e3f;

정답 : b, c, answer, f
16 changes: 16 additions & 0 deletions src/kwonseongmin/report1/Report1_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//2-7. 다음 문장들의 출력 결과를 적으세요. 오류가 있는 문장의 경우, '오류' 라고 적으세요.
System.out.println("1" + "2");
System.out.println(true+"");
System.out.println('A' + 'B');
System.out.println('1' + 2);
System.out.println('1' + '2');
System.out.println('J' +"ava");
System.out.println(true + null);

정답 : 12
true
131
51
99
Java
오류
23 changes: 23 additions & 0 deletions src/kwonseongmin/report1/Report1_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kwonseongmin.report1;
//2-8. 아래는 변수 x, y, z의 값을 서로 바꾸는 예제이다. 결과와 같이 출력되도록 코드를 넣으세요.
//예상 결과 : x=2, y=3, z=1

class Exercise2_8 {
public static void main(String[] args){

int x = 1;
int y = 2;
int z = 3;
/*
알맞은 코드를 넣어 완성하세요.
*/
int temp = x;
x = y;
y = z;
z = temp;

System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("z="+z);
}
}
14 changes: 14 additions & 0 deletions src/kwonseongmin/report2/Report2_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//3-1. 다음 중 형변환을 생략할 수 있는 것은? (모두 고르시오)

byte b = 10;
char ch = 'A';
int i = 100;
long l = 1000L;

b = (byte)i;
ch = (char)b;
short s = (short)ch;
float f = (float)l;
i = (int)ch;

정답 : i = (int)ch;, float f = (float)l;
Loading