7월 26일, TIL

코코·2023년 7월 26일
0

TIL(Today I Learned)

목록 보기
2/19
post-thumbnail

nextLine()과 next() 차이점

  • Scanner와 함께 자주 쓰이는 메소드.
  • nextLine()은 Scanner를 통해 입력받은 전부를 리턴하는 반면 next()는 스페이스(공백) 전까지만 리턴함.
EX)
<입력>

    Scanner sc = new Scanner(System.in);

    System.out.print("문자열입력: ");
    String str1 = sc.nextLine();
    System.out.println(str1);

    System.out.print("문자열입력: ");
    String str2 = sc.next();
    System.out.println(str2);
EX)
<출력>

    문자열입력: 안녕하세요 반갑습니다. //nextLine() 사용
    안녕하세요 반갑습니다.
    문자열입력: 안녕하세요 반갑습니다.	//next() 사용
    안녕하세요

Integer.MIN_VALUE, Integer.MAX_VALUE

  • 32비트에서 Int 정수 범위는 -2,147,483,648 ~ 2,147,483,647 이다.

  • 따라서 32비트 Int 정수의 최대값은 2,147,483,647 이고, 최소값은 -2,147,483,648 이다.
    (64비트에서도 정수의 경우 32비트와 마찬가지로 4byte라서 같다.)

  • Integer 클래스의 MAX_VALUE, MIN_VALUE를 사용하면 정수의 최대값(2,147,483,647)과 최소값(-2,147,483,648)을 바로 출력할 수 있다.

출처 - https://hydroponicglass.tistory.com

profile
Just Do It

0개의 댓글