자바_기초
For + Scanner : 정수를 무한적으로 입력받다가 8의 배수가 5개 입력되면 반복문 종료하기
잠수콩
2019. 5. 21. 15:19
// 정수를 무한적으로 입력받다가 8의 배수가 5개 입력되면 반복문 종료하기
import java.util.Scanner;
public class ForEx_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = 0;
for(;;) {
System.out.println("정수입력1 > ");
int b = sc.nextInt();
if (b % 8 == 0) {
count++;
}
if (count == 5) break;
}
System.out.println("반복종료11!");
System.out.println("=========================");
Scanner input2 = new Scanner(System.in);
int count2 = 0;
while(count2 != 5) {
System.out.println("정수입력2 > ");
int c = input2.nextInt();
if (c % 8 == 0) {
count2++;
}
}
System.out.println("반복종료22!");
}
}