나의 기록, 현진록

[Java] 이것이 자바다 3단원 확인문제 본문

Programming/ETC

[Java] 이것이 자바다 3단원 확인문제

guswlsdk 2017. 7. 21. 15:51
반응형

1. 연산자와 연산식에 대한 설명 중 틀린 것은 무엇입니까?

  1. 연산자는 피연산자 수에 따라 단한, 이항, 삼항 연산자로 구분된다.
  2. 비교 연산자와 논리 연산자의 산출 타입은 boolean (true/false)이다.
  3. 연산식은 하나 이상의 값을 산출할 수도 있다.
  4. 하나의 값이 올 수 있는 자리라면 연산식도 올 수 있다.

2. 다음 코드를 실행했을 때 출력 결과는 무엇입니까?


1
2
3
4
5
6
7
8
public class Exercise02{
    public static void main (String[] args){
        int x=10;
        int y=20;
        int z=(++x) + (y--);
        System.out.println(z);
    }
}
cs


정답 : 31


3. 다음 코드를 실행했을 때 출력 결과는 무엇입니까?


1
2
3
4
5
6
7
8
public class Exercise03 {
    public static void main(String[] args){
        int score=85;
        String result = (!(score>90)) ? "가":"나";
        System.out.println(result);
    }
}
 
cs


정답 : 가


4. 534자루의 연필을 30명의 학생들이게 똑같은 개수로 나누어 줄 때 학생당 몇 개를 가질 수 있고, 최종적으로 몇 개가 남는지를 구하는 코드입니다. (#1)과 (#2)에 들어갈 알맞은 코드를 작성하세요.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Exercise04 {
    public static void main (String[] args){
        int pencils=534;
        int students=30;
        
        //학생 한 명이 가지는 연필 수
        int pencilsPerStudent=(      #  );
        System.out.println(pencilsPerStudent);
        
        //남은 연필 수
        int pencilsLeft=(    #2     );
        System.out.println(pencilsLeft);
    }
}
 
cs


정답 :

#1 = pencils/students

#2 = pencils%students


5. 다음은 십의 자리 이하를 버리는 코드입니다. 변수 value의 값이 356이라면 300이 나올 수 있도록 (#1)에 알맞은 코드를 작성하세요.(산술 연산자만 사용하세요.)


1
2
3
4
5
6
7
public class Exercise05 {
    public static void main (String[] args){
        int value = 356;
        System.out.println(     #1     );
    }
}

cs


정답 :

#1 = value-=value%100


6. 다음 코드는 사다리꼴의 넓이를 구하는 코드입니다. 정확히 소수자릿수가 나올 수 있도록 (#1)에 알맞은 코드를 작성하세요.


1
2
3
4
5
6
7
8
9
public class Exercise06 {
    public static void main (String[] args){
        int lengthTop=5;
        int lengthBottom=10;
        int height=7;
        double area=(   #  );
        System.out.println(area);
    }
}
cs


정답 : 

#1 = 7*(lengthTop+lengthBottom)/2


7. 다음 코드는 비교 연산자와 논리 연산자의 복합 연산식입니다. 연산식의 출력 결과를 괄호() 속에 넣으세요.


1
2
3
4
5
6
7
8
9
public class Exercise07 {
    public static void main(String[] args){
        int x=10;
        int y=5;
        
        System.out.println( (x>7&& (y<=5) );
        System.out.println( (x%== 2|| (y%!= 1));
    }
}
cs


정답 : 

true

false



8. 다음은 % 연산을 수행한 결과값에 10을 더하는 코드입니다. NaN 값을 검사해서 올바른 결과가 출력될 수 있도록 (#1)에 들어갈 NaN을 검사하는 코드를 작성하세요.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Exercise08 {
    public static void main(String[] args){
        double x=5.0;
        double y=0.0;
        
        double z=x%y;
        
        if(    #){
            System.out.println("0.0으로 나눌 수 없습니다.");
        }
        else{
            double result=z+10;
            System.out.println("결과: "+result);
        }
    }
}
 
cs


정답 : 

#1 = Double.isNaN(z)

반응형