본문 바로가기

IT, 인터넷/JAVA, 스프링부트

자바 Scanner로 숫자 10개 입력 받아 합 구하기

반응형

import java.util.Scanner;

 

public class array {

 

    public static void main(String[] args) {

 

        int number1=0, number2=0, number3=0, number4=0, number5=0, number6=0, number7=0, number8=0,

                number9=0, number10=0, result;

        

        Scanner sc = new Scanner(System.in);

        

        System.out.println("배열(1)을 입력 하세요 >>");

        number1 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(2)을 입력 하세요 >>");

        number2 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(3)을 입력 하세요 >>");

        number3 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(4)을 입력 하세요 >>");

        number4 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(5)을 입력 하세요 >>");

        number5 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(6)을 입력 하세요 >>");

        number6 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(7)을 입력 하세요 >>");

        number7 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(8)을 입력 하세요 >>");

        number8 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(9)을 입력 하세요 >>");

        number9 = Integer.parseInt(sc.next()) * 3;

        

        System.out.println("배열(10)을 입력 하세요 >>");

        number10 = Integer.parseInt(sc.next()) * 3;

        

        result = number1 + number2 + number3 + number4 + number5 + number6 + number7 + number8 + number9 + number10;

        

        System.out.println("result : " + result);

        

    }

}

반응형