inblog logo
|
jay0628
    Java

    [Java] 3.1. 더하기

    김주희's avatar
    김주희
    Feb 04, 2025
    [Java] 3.1. 더하기
    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.print("첫 번째 숫자를 입력하시오: "); x = sc.nextInt(); System.out.print("두 번째 숫자를 입력하시오: "); y = sc.nextInt(); sum = x + y; System.out.println(sum); } }
    notion image
     
    💡
    변수를 선언하면 (=/= 초기화) int는 기본값으로 0, String(참조형)은 null이 들어간다.
     
    Share article

    jay0628

    RSS·Powered by Inblog