티스토리 뷰

Error Case

[Java] int 와 long 차이

HoSeongYu 2021. 12. 18. 13:18

[Code]

import java.util.*;
class Main {  
  public static void main(String args[]) { 
    Scanner scan = new Scanner(System.in);
    int S = scan.nextInt();
    System.out.println(maxcnt(S));
  } 

  public static int maxcnt(int S){
    int max = 0;
    int cnt = 0;
    int i=1;
    while(max <= S){
      max += i;
      i++;
      cnt++;
    }
    cnt--;
    return cnt;
  }
}

[Error Message]

java.util.InputMismatchException


[Solution]

타입변경 : int -> long

 

[결론]

int는

-2147483648 ~ 2147483647

long은

-9223372036854775808 ~ 9223372036854775807

까지 표현할 수 있습니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/07   »
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
글 보관함