자바기반응용프로그래밍 - 반복문
·
Language/JAVA
for문 구성 형식: 초기문, 조건식, 반복 후 작업, 작업문 while문 구성형식: 조건식, 작업문 // -1이 입력될때까지 반복 import java.util.Scanner; public class WhileSample { public static void main(String[] args) { int n; int cnt = 0; int sum = 0; Scanner scanner = new Scanner(System.in); System.out.println("정수를 입력하고 마지막에 -1을 입력하세요."); n = scanner.nextInt(); while( n != -1) { sum += n; cnt++; n = scanner.nextInt(); } if(cnt == 0) { System.ou..