[자바 연산자] 6. 더하기

김건우's avatar
Feb 04, 2025
[자바 연산자] 6. 더하기
💡
Scanner 클래스는 키보드로부터 바이트 값을 받아서 분리자를 이용하여 각 바이트들을 토큰으로 분리한다.
package ex02; import java.util.Scanner; public class Add2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 키보드 입력 받기 준비 // 변수의 선언 null 값이 들어감. // int를 선언하면 0이 들어감. int x; int y; int sum; System.out.println("첫 번째 숫자를 입력하시오: "); x = sc.nextInt(); System.out.println("두 번째 숫자를 입력하시오: "); y = sc.nextInt(); sum = x + y; System.out.println(sum); } }
  • 정수를 읽으려면 nextInt() 를 사용한다.
notion image
Share article

gunwoo