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/kimhyunho/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2-4번 문제

정답 : double d = 1.4e3f;
3 changes: 3 additions & 0 deletions src/kimhyunho/report1/Report1_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2-7번 번 문제

정답 : System.out.println(true + null); // 오류
19 changes: 19 additions & 0 deletions src/kimhyunho/report1/Report1_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kimhyunho.report1;
// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수
public class Report1_3 {
public static void main(String[] args){
int x = 1;
int y = 2;
int z = 3;
/*
x = 2;
y = 3;
z = 1;
*/
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("z="+z);
}
}
//예상 결과 : x=2, y=3, z=1

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

정답 : b = (byte)i; , ch = (char)b;
30 changes: 30 additions & 0 deletions src/kimhyunho/report2/Report2_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kimhyunho.report2;

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);
// 정답 : false // x값 미충족
System.out.println(y += 10 - x++);
// 정답 : 15 - 2 = 13
System.out.println(x += 2);
// 정답 : 4
System.out.println(!('A' <= c && c <= 'Z'));
// 정답 : true // 값은 false 이지만 ! 으로 true
System.out.println('C' - c);
// 정답 : 2
System.out.println('5' - '0');
// 정답 : 5
System.out.println(c + 1);
// 정답 : 66
System.out.println(++c);
// 정답 : B
System.out.println(c++);
// 정답 : A
System.out.println(c);
// 정답 : 'A'
}
}
11 changes: 11 additions & 0 deletions src/kimhyunho/report2/Report2_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kimhyunho.report2;

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

//3-4. 아래의 코드는 사과를 담는데 필요한 바구니(버켓)의 수를 구하는 코드이다.
//만일 사과의 수가 123개이고 하나의 바구니에는 10개의 사과를 담을 수 있다면, 13개의 바구니가 필요할 것이다.
//알맞은 코드를 넣으시오.
class Report2_4 {
public static void main(String[] args){
int numOfApples = 123; // 사과의 개수
int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수)
int numOfBucket = (numOfApples/sizeOfBucket+1); // 모든 사과를 담는데 필요한 바구니의 수

// int appples = 123;
// int boxSize = 10;
// System.out.println((int)Math.ceil((double)appples/boxSize));
//

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

//3-5. 아래는 변수 num의 값에 따라 '양수', '음수', '0'을 출력하는 코드이다.
//삼항연산자를 이용해서 빈칸에 알맞은 코드를 넣으시오.
//Hint : 삼항 연산자를 두 번 사용할 것!
class Report2_5{
public static void main(String[] args){
int num = 10;
String a = "";

if(num >=0) a = "양수";
else a = "음수";
System.out.println(a);
}
}
//예상 결과 : 양수
17 changes: 17 additions & 0 deletions src/kimhyunho/report2/Report2_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kimhyunho.report2;

//3-6. 아래는 화씨(Fahrenheit)를 섭씨(Celcius)로 변환하는 코드이다.
//변환 공식이 'C = 5/9*(F-32)'라고 할 때, 빈 칸에 알맞은 코드를 넣으시오.
// 단, 변환값은 소수점 셋째자리에서 반올림하며, Math.round() 함수를 사용하지 않고 처리할 것!
class Report2_6{
public static void main(String[] args){
int fahrenheit = 100;
float celcius = (int)(5/9f*(fahrenheit-32)*100)*0.01f+0.01f;

System.out.println("Fahrenheit:"+fahrenheit);
System.out.println("Celcius:"+celcius);
}
}


//예상 결과 : Fahrenheit:100, Celcius:37.78
22 changes: 22 additions & 0 deletions src/kimhyunho/report3/Report3_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 4-1번 문제

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

char형 변수 ch가 공백이나 탭이 아닐 때 true인 조건식
ch !='' || ch ==""
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인 조건식
int year = 400


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


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

//4-10. 다음은 숫자맞추기 게임을 작성한 것이다. 1과 100사이의 값을 반복적으로 입력해서
//컴퓨터가 생각한 값을 맞추면 게임이 끝난다.
//사용자가 값을 입력하면, 컴퓨터는 자신이 생각한 값과 비교해서 결과를 알려준다.
//사용자가 컴퓨터가 생각한 숫자를 맞추면 게임이 끝나고 몇 번 만에 숫자를 맞췄는지 알려준다.
class Report3_10 {
// 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) {
else {
System.out.println("맞췄습니다.");
System.out.println("시도는 "+count+"번 입니다.");
break;
}
}
} while(true); //무한반복문
} // end of main
} // end of class
//예상 결과
//1과 100사이의 값을 입력하세요 : 50
//더 큰 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 75
//더 큰 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 87
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 80
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 77
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 76
//맞혔습니다.
//시도횟수는 6번입니다.
14 changes: 14 additions & 0 deletions src/kimhyunho/report3/Report3_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kimhyunho.report3;

//4-2. 1부터 20까지의 정수중에서 2 또는 3의 배수가 아닌 수의 총합을 구하세요.
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);
}
}

16 changes: 16 additions & 0 deletions src/kimhyunho/report3/Report3_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kimhyunho.report3;

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

for (int i = 1; i <=10; i++) {
sum += i+(i+1);
totalSum = sum;
}
System.out.println("totalSum="+totalSum);
}
}

27 changes: 27 additions & 0 deletions src/kimhyunho/report3/Report3_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kimhyunho.report3;

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

// while (true, sum >= 100, s++, s=-s);
// num = sum * s;


if (num % 2 == 0) {
num = 1 * -s;
} else {
num = s;
}
sum += num;

System.out.println("num=" + num);
System.out.println("sum=" + sum);

}
}

36 changes: 36 additions & 0 deletions src/kimhyunho/report3/Report3_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kimhyunho.report3;

//4-5. 다음의 for문을 while문으로 변경하세요.
class Report3_5 {
public static void main(String[] args) {
int i = 0, j = 0;

while (i < 5) {

// 행 열
// i = 0 ,j = 0
// i = 0 ,j = 1
// i = 1 ,j = 1
// i = 1 ,j = 2
// i = 2 ,j = 2
// i = 2 ,j = 3
// i = 3 ,j = 3
// i = 3 ,j = 4
// i = 4 ,j = 4
// i = 4 ,j = 5
// i = 5 ,j = 5


while (j <= i) {
System.out.print('*');
j++;
}

i++;
j = 0;
System.out.println();
}//end of main
} // end of class
}


15 changes: 15 additions & 0 deletions src/kimhyunho/report3/Report3_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kimhyunho.report3;

//3-6 두 개의 주사위를 던졌을 때, 눈의 합이 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));
}
}
}
}
}
21 changes: 21 additions & 0 deletions src/kimhyunho/report3/Report3_7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package kimhyunho.report3;

//4-7. 숫자로 이루어진 문자열 str이 있을 때, 각 자리의 합을 더한 결과를 출력하는 코드를 완성하세요.
//만일 문자열이 "12345"라면, ‘1+2+3+4+5’의 결과인 15를 출력이 출력되어야 합니다.
class Report3_7 {
public static void main(String[] args) {
String str = "12345";
int sum = 0;

for (int i = 0; i < str.length(); i++) {
for (int j = 0; j <= 5; j++) {
if (sum <= 5);



}
}

System.out.println("sum=" + sum);
}
}//예상 결과 : sum=15
9 changes: 9 additions & 0 deletions src/kimhyunho/report3/Report3_8.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kimhyunho.report3;

//4-8. Math.random()을 이용해서 1부터 6 사이의 임의의 정수를 변수 value에 저장하는 코드를 완성하세요.
class Report3_8 {
public static void main(String[] args) {
int value = (int)(Math.random() * 6 + 1);
System.out.println("value:"+value);
}
}
23 changes: 23 additions & 0 deletions src/kimhyunho/report3/Report3_9.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kimhyunho.report3;

//4-9. int 타입의 변수 num이 있을 때, 각 자리의 합을 더한 결과를 출력하는 코드를 완성하세요.
//만일 변수 num의 값이 12345라면, ‘1+2+3+4+5’의 결과인 15를 출력하세요.
//문자열로 변환하지 말고 숫자로만 처리하세요.
class Report3_9 {
public static void main(String[] args) {
int num = 12345;
int sum = 0;
while (num > 0) {

// 12345 $ 10 = 5
// 1234 $ 10 = 4
// 123 $ 10 = 3
// 12 $ 10 = 2
// 1 $ 10 = 1

sum += num%10;
num /=10;
}
System.out.println("sum="+sum);
}
} //예상 결과 : sum=15
Binary file added src/kimhyunho/report3/Untitled.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/kimhyunho/report4/Report4_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 5-1 번 문제

정답 : int[] arr = {1,2,3,};
3 changes: 3 additions & 0 deletions src/kimhyunho/report4/Report4_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 5-2 번 문제

정답 : 20
Loading