문제
변수에 값을 저장할 때 발생하는 overflow와 underflow를 실습하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요
프로그램의 실행순서 및 실행상태
1 public static void main( String[] args ) {
2 final int max = +2147483647;
3 final int min = -2147483648;
4 int overflow = max + 1;
5 int underflow = min - 1;
6 System.out.println( "max = " + max );
max = 2147483647
7 System.out.println( "max + 1 = " + overflow + " ( overflow 발생 )" );
max + 1 = -2147483648 ( overflow 발생 )
8 System.out.println( "min = " + min );
min = -2147483648
9 System.out.println( "min - 1 = " + underflow + " ( underflow 발생 )" );
min - 1 = 2147483647 ( underflow 발생 )
10 }
프로그램 코드
public class OverflowUnderflow
{
1 public static void main( String[] args ) {
2 final int max = +2147483647;
3 final int min = -2147483648;
4 int overflow = max + 1;
5 int underflow = min - 1;
6 System.out.println( "max = " + max );
7 System.out.println( "max + 1 = " + overflow + " ( overflow 발생 )" );
8 System.out.println( "min = " + min );
9 System.out.println( "min - 1 = " + underflow + " ( underflow 발생 )" );
10 }
}