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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hanghae-java-study-12
Submodule hanghae-java-study-12 added at e78227
11 changes: 11 additions & 0 deletions hanghae-java-study-12.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
8 changes: 8 additions & 0 deletions src/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/choiwonbin/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2-4번 문제

정답 :
정답 : 3
1 change: 1 addition & 0 deletions src/hanghae-java-study-12
Submodule hanghae-java-study-12 added at 701e0f
11 changes: 11 additions & 0 deletions src/hanghae-java-study-12.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
13 changes: 13 additions & 0 deletions src/jominsung/report1/Report1_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
2-4번 문제

//2-4. 다음 중 변수를 잘못 초기화 한 것은?
byte b = 256;
char c = '';
char answer = 'no';
float f = 3.14
double d = 1.4e3f;

정답 : byte b = 256;는 128까지인데 256을 입력해서 안됩니다.
char c = '';는 빈칸만 있어서 안됩니다.
char answer = 'no';는 문자 코드라 한개만 입력해야되는데 no로 두개라 안됩니다.
float f = 3.14은 ;도 없고 float인데 뒤에 f도 붙지 않아서 안됩니다.
11 changes: 11 additions & 0 deletions src/jominsung/report1/Report1_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2-7번 문제

//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); ( 오류 )
36 changes: 36 additions & 0 deletions src/jominsung/report1/Report1_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jominsung.report1;
// 2-8 번 문제 <- 이렇게 문제 번호 작성 필수
public class Report1_3 {
public static void main(String[] args) {
AddClass addClass = new AddClass();
addClass.test();
//2-8. 아래는 변수 x, y, z의 값을 서로 바꾸는 예제이다. 결과와 같이 출력되도록 코드를 넣으세요.
int x = 1;
int y = 2;
int z = 3;

int tmp = 0;

tmp = x;
x = y;
y = z;
z = tmp;



System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("z="+z);
}
}
//예상 결과 : x=2, y=3, z=1


// 필요하다면 클래스 추가
class AddClass {
void test() {
System.out.println("AddClass.test");


}
}
117 changes: 117 additions & 0 deletions src/jominsung/report2/Report2_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package jominsung.report2;
public class Report2_2 {
public static void main(String[] args) {

// 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;
// 정답 float f = (float)l; , i = (int)ch;
}
}

//3-2. 다음 연산의 결과와 그 이유를 적으세요.
class Report3_2{
public static void main(String[] args){
int x = 2;
int y = 5;
char c = 'A'; // 'A'의 문자코드는 65

//true 이며 x < 0 && x > 2 만 보면 and 코드 이기도 하지만 원래 틀렸는데 false가 나오겠지만 앞에 y >= 5 || 가 OR코드 이며 맞는거기에 true가 나옴
System.out.println(y >= 5 || x < 0 && x > 2);
//13 이며 y += 10 을 했을때 15가 되며 - x++ 은 ++이 더하기 1 과 같은데 x++ 이기때문에 x값을 먼저 가져와서 그냥 2이기 때문이다.
System.out.println(y += 10 - x++);
//5 이며 원래 같으면 2 + 2 같지만 위에 x++ 에서 후위 전산때문에 +1이 되서 3 + 2가 되서 5이다
System.out.println(x += 2);
//false 이며 원래는 둘다 맞는 공식이라 true 가 나와야 되는데 ! 가 not 코드라 flase가 된다.
System.out.println(!('A' <= c && c <= 'Z'));
//2 이며 'C'가 아스키코드로 67 이고 char c = 'A'라고 정의 했는데 'A'의 문자코드가 65 이기에 실질적으로 67 - 65 라서 이다.
System.out.println('C' - c);
//5 이며 문자열 - 문자열 이라 5가 나옵니다.
System.out.println('5' - '0');
//66이며 여기서 c가 'A' 인데 문자코드로 65에 +1을 해서 문자코드가 66이 되기 때문이다.
System.out.println(c + 1);
//B이며 전위 연산인데 ++가 +1 하는거와 같기때문에 c = "A' = 65에 +1을 하기때문이다.
System.out.println(++c);
//B가 나오며 원래 c++이 위에 있었으면 A가 나오겠지만 앞서 ++c를 먹고 내려와서 B가 나온다.
System.out.println(c++);
//C가 나오며 앞에 c++에서 c가 먹지가 않았는데 이 ++값이 뒤에 c값에 들어가서 +1되가지고 문자 코드가 67이 돼서 C가 된다.
System.out.println(c);
}
}



//3-3. 아래는 변수의 num 값 중에서 백의 자리 이하를 버리는 코드이다.
//만일 변수 num의 값이 '456'이라면 '400'이 되고, '111'이라면 '100'이 된다.
//알맞은 코드를 넣으시오.
class Report3_3 {
public static void main(String[] args){
int num = 456;
// 실수가 아닌 정수인 int를 써서 100을 나눠도 소숫점이 안나오기에 다시 100을 곱하면 400이 됨
System.out.println(num/100*100);
}
}



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

//한 바구니당 10개씩 담을수 있으니 여기서 사과의 개수 나누기 바구니의 크기 값을 하면 12가 되는데 여기서 +1을 해야되는 상황인데
// 여기서 혹여나 값을 변형 했을때 그거에 맞게 바구니의 수도 늘려야 되기 때문에 조건문을 썻고 나머지가 줄어들수록 바구니의 갯수도 정확해해질수 있기에 나머지 구하는 연산을 썻다.

System.out.println("필요한 바구니의 수 :"+numOfBucket);
}
}
//예상 결과 -> 필요한 바구니의 수 :13



//3-5. 아래는 변수 num의 값에 따라 '양수', '음수', '0'을 출력하는 코드이다.
//삼항연산자를 이용해서 빈칸에 알맞은 코드를 넣으시오.
//Hint : 삼항 연산자를 두 번 사용할 것!
class Report3_5{
public static void main(String[] args){
int num = 10;
// 일단 두개는 어떻게 써야되는지 몰라서 구글링을 해서 확인 해서 이렇게 써봣는데 양수는 나오게 했는데 값이 달라졌을때 값을 바꾸는건 어떻게 해야될지 모르겟습니다.
System.out.println(num >= 0 ?(num >= 0 ? "양수" : "0" ) : "음수");
}
}
//예상 결과 : 양수



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

if (b%10 >= 5) {
b = b + 10 - 7;
}
double Celcius = b * 0.001;

System.out.println("Fahrenheit:"+fahrenheit);
System.out.println("Celcius:"+ Celcius );
}
}
//예상 결과 : Fahrenheit:100, Celcius:37.78

54 changes: 54 additions & 0 deletions src/jominsung/report3/Report3_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
4-1. 다음의 문장들을 조건식으로 표현해보세요.

int형 변수 x가 10보다 크고 20보다 작을 때 true인 조건식
int x = 15;
if (10 < x && x < 20) {
System.out.println(true);
} else {
System.out.println(false);
}

char형 변수 ch가 공백이나 탭이 아닐 때 true인 조건식
char ch = 'a';

if (ch != ' ' && ch != '\t' ) {
System.out.println(true);
}else {
System.out.println(false);
}

char형 변수 ch가 'x' 또는 'X'일 때 true인 조건식
char ch = 'x';
if (ch == 'x' || ch == 'X'){
System.out.println(true);
}else {
System.out.println(false);
}

char형 변수 ch가 숫자('0'~'9')일 때 true인 조건식
char ch = '5';
if ('0' <= ch && ch <= '9') {
System.out.println(true);
} else {
System.out.println(false);
}

char형 변수 ch가 영문자(대문자 또는 소문자)일 때 true인 조건식
char ch = 'c';
if ('a' <= ch && ch <= 'z') {
System.out.println(true);
} else if ('A' <= ch && ch <= 'Z') {
System.out.println(true);
}else {
System.out.println(false);
}

int형 변수 year가 400으로 나눠떨어지거나 또는 4로 나눠떨어지고 100으로 나눠떨어지지 않을때 true인 조건식
int year = 400;
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)){
System.out.println(true);
};
}



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

public class Report3_10 {
public static void main(String[] args) {
//4-10. 다음은 숫자맞추기 게임을 작성한 것이다. 1과 100사이의 값을 반복적으로 입력해서
//컴퓨터가 생각한 값을 맞추면 게임이 끝난다.
//사용자가 값을 입력하면, 컴퓨터는 자신이 생각한 값과 비교해서 결과를 알려준다.
//사용자가 컴퓨터가 생각한 숫자를 맞추면 게임이 끝나고 몇 번 만에 숫자를 맞췄는지 알려준다.


// 1~100사이의 임의의 값을 얻어서 answer에 저장한다.
int answer = (int)(Math.random() * 100);
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
//예상 결과
//1과 100사이의 값을 입력하세요 : 50
//더 큰 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 75
//더 큰 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 87
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 80
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 77
//더 작은 수를 입력하세요.
//1과 100사이의 값을 입력하세요 : 76
//맞혔습니다.
//시도횟수는 6번입니다.
Loading