Notice
Recent Posts
Recent Comments
Link
«   2025/10   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

UniCode

[이것이 자바다]CH03.연산자(확인문제풀이) 본문

이것이 자바다

[이것이 자바다]CH03.연산자(확인문제풀이)

Uni_code 2021. 3. 21. 12:33

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

① 연산자는 피연산자의 수에 따라 단항, 이항, 삼항 연산자로 구분된다.

② 비교 연산자와 논리 연산자의 산출 타입은 boolean(true/false) 이다.  

③ 연산식은 하나 이상의 값은 산출할 수도 있다.

④ 하나의 값이 올 수 있는 자리라면 연산식도 올 수 있다.

 

③ 연산식은 반드시 하나의 값을 선출한다. 그렇기 때문에 하나의 값이 올 수 있는 곳이면 어디든지 값 대신에 연산식을 사용할 수 있다.

 

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

[Exercise02.java]
public class Exercise02 {
   public static void main(String[] args) {
       int x = 10;
       int y = 20;
       int z = (++x) + (y--);
       System.out.println(z); 
   }
}

☞ 31

    11 + 20 = 31  

 

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

[Exercise03.java]
public class Exercise03 {
   public static void main(String[] args){
      int score = 85;
      String result = (!(score>90))? "가" : "나";
      System.out.println(result); 
   }
}

☞ 가

(!(score>90))? "가" : "나" : score 값이 90보다 크지않다 참일 경우 가, 거짓일 경우 나

 

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

[Exercise04.java]
public class Exercise04 {
   public static void main(String[] args){
      int pencils = 534;
      int students = 30;

      int pencilsPerStudent = (  #1  ) //학생 한 명이 가지는 연필 수
      System.out.println(pencilsPerStudent);

      int pencilsLeft = (  #2  ) //남은 연필 수
      System.out.println(pencilsLeft); 

   }
}

☞ #1 : pencils / students     #2 : pencils % students

 

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

[Exercise05.java]
public class Exercise05 {
   public static void main(String[] args){
      int value = 356;
      System.out.println( #1 ); 
   }
}

☞ #1 : value - (value%100)   OR   (value/100) * 100

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

[Exercise06.java]
public class Exercise06 {
   public static void main(String[] args){
      int lengthTop = 5;
      int lengthBottom = 10;
      int height = 7;
      double area = (  #1  );
      System.out.println(area); 
   }
}

☞ #1 : (double) (lengthTop + lengthBottom) / 2 * height

 

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

[Exercise07.java]
public class Exercise07 {
   public static void main(String[] args){
      int x = 10;
      int y = 5;
     

      System.out.println( ( x>7 ) && ( y<=5 ) );                    ------------(      #1      )
      System.out.println( ( x % 3 == 2 ) || ( y%2 != 1 ) );        ------------(      #2      )

   }
}

☞ #1 : true  #2 : false

 

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

[Exercise08.java]
public class Exercise08 {
   public static void main(String[] args){
      double x = 5.0;
      double y = 0.0;

      double z = x % y;
     
      if(   #1   ){
         System.out.println("0.0으로 나눌 수 없습니다.");
       } else {
         double result = z + 10;
         System.out.println("결과 :  " + result );
       }
   }
}

☞ Double.isNaN(z)