728x90 320x100 while문1 while문 사용하여 1부터 n까지 정수의 합 구하기 (chap01/SumWhile) package chap01; import java.util.Scanner; public class SumWhile { //while 문으로 1,2,... n의 합을 구함 public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("1부터 n까지의 합을 구합니다."); System.out.print("n값 : "); int n = scan.nextInt(); int sum = 0; int i = 1; while (i 2022. 10. 6. 이전 1 다음 728x90 320x100