자바기초 #2 intValue()

minsekim1·2022년 6월 6일

java

목록 보기
2/13

위 문제는 intValue()를 사용하지 않고도 int로 해결할 수 있다. 하지만 일반적으로 점수는 Double를 쓰므로 Double에서 .intValue() 메서드를 통해서 int형으로 출력을 해주었다.


public class Score {
  public static void main(String[] args) {
    /* 1. 변수 생성 */
    Double math = 96.0;
    Double science = 88.0;
    Double english = 76.0;
    /* 2. 결과 출력 */
    System.out.println("수학: " + math.intValue());
    System.out.println("과학: " + science.intValue());
    System.out.println("영어: " + english.intValue());
  }
}

이외에 Double의 메서드는 다음과 같다.

문제 출처

https://cloudstudying.kr/codes/66690#code-output

profile
안녕하세요! 백엔드로 변신중인 4년차 풀스택 개발자 민세킴입니다.

0개의 댓글