diff --git a/src/report/report1.txt b/src/report/report1.txt new file mode 100644 index 0000000..a47924a --- /dev/null +++ b/src/report/report1.txt @@ -0,0 +1,32 @@ +//2-4. 다음 중 변수를 잘못 초기화 한 것은? 1 2 3 4 +byte b = 256; +char c = ''; +char answer = 'no'; +float f = 3.14 +double d = 1.4e3f; + +//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); 오류 + +/2-8. 아래는 변수 x, y, z의 값을 서로 바꾸는 예제이다. 결과와 같이 출력되도록 코드를 넣으세요. +public class Exercise2_8{ + public static void main(String[] args){ + int x = 1; + int y = 2; + int z = 3; + tem; = x; + x= y; + y= z; + z= tem; + System.out.println("x="+x); + System.out.println("y="+y); + System.out.println("z="+z); + } +} +//예상 결과 : x=2, y=3, z=1ㄹㄹ \ No newline at end of file diff --git a/src/report/report2.txt b/src/report/report2.txt new file mode 100644 index 0000000..e2cbdf8 --- /dev/null +++ b/src/report/report2.txt @@ -0,0 +1,92 @@ +byte b = 10; +char ch = 'A'; +int i = 100; +long l = 1000L; +//3-1. 다음 중 형변환을 생략할 수 있는 것은? (모두 고르시오) 4,5 +b = (byte)i; +ch = (char)b; +short s = (short)ch; +float f = (float)l; +i = (int)ch; + + + +//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); ture + System.out.println(y += 10 - x++); 13 + System.out.println(x += 2); 5 + System.out.println(!('A' <= c && c <= 'Z'));false + System.out.println('C' - c); 2 + System.out.println('5' - '0'); + System.out.println(c + 1); 66 + System.out.println(++c); 66 + System.out.println(c++); 65 + System.out.println(c); 66 + } +} + + + +//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); + } +} + + + +//3-4. 아래의 코드는 사과를 담는데 필요한 바구니(버켓)의 수를 구하는 코드이다. +//만일 사과의 수가 123개이고 하나의 바구니에는 10개의 사과를 담을 수 있다면, 13개의 바구니가 필요할 것이다. +//알맞은 코드를 넣으시오. +class Exercise3_4{ + public static void main(String[] args){ + int numOfApples = 123; // 사과의 개수 + int sizeOfBucket = 10; // 바구니의 크기(바구니에 담을 수 있는 사과의 개수) + int numOfBucket = (/*빈 칸*/); // 모든 사과를 담는데 필요한 바구니의 수 + + System.out.println("필요한 바구니의 수 :"+((Math.ceil((double)numOfApples/numOfBucket))*10); + } +} +//예상 결과 -> 필요한 바구니의 수 :13 + + + +//3-5. 아래는 변수 num의 값에 따라 '양수', '음수', '0'을 출력하는 코드이다. +//삼항연산자를 이용해서 빈칸에 알맞은 코드를 넣으시오. +//Hint : 삼항 연산자를 두 번 사용할 것! +class Exercise3_5{ + public static void main(String[] args){ + int num = 10; + + System.out.println(/*빈 칸*/); + } +} +//예상 결과 : 양수 + + + +//3-6. 아래는 화씨(Fahrenheit)를 섭씨(Celcius)로 변환하는 코드이다. +//변환 공식이 'C = 5/9*(F-32)'라고 할 때, 빈 칸에 알맞은 코드를 넣으시오. +// 단, 변환값은 소수점 셋째자리에서 반올림하며, Math.round() 함수를 사용하지 않고 처리할 것! +class Exercise3_6{ + public static void main(String[] args){ + scanf("%d",&celcius); + int fahrenheit = 100; + int input, tenTousand, thousand, hubdred: + float celcius = (5/9*(fahrenheit -32))) + celcius = (tenThousend* 10000) +(thousand* 1000) + ((hundred >=5) * 5000) ; + System.out.println("Fahrenheit:"+fahrenheit); + System.out.println("Celcius:"+celcius); + } +} +//예상 결과 : Fahrenheit:100, Celcius:37.78 \ No newline at end of file