import java.util.Scanner;
java.util안에 있는 scanner을 이용합니다
Scanner sc = new Scanner(System.in);
을 이용해 클래스 객체를 생성합니다
int a = sc.nextInt();
이런식으로 Scanner객체를 사용합니다
Scanner sc = new Scanner(System.in);
while(true) {
System.out.print("a변수에 들어갈 값 입력하세요 : "); //
int a = sc.nextInt();
System.out.println("a : " + a);
if(100<= a && a <= 1000) {
System.out.printf("a 값이 %d 입니다\n",a);
for(int i = 0; i < 3; i++) {
System.out.print("Big! ");
}break;
}else if(a <= 100) {
System.out.printf("a 값이 %d 입니다\n",a);
for(int i = 0; i < 3; i++) {
System.out.print("Small! ");
}break;
}else if(a >= 1000) {
System.out.println("a의 값을 1000이하의 값으로 해주세요");
for(int i = 0; i < 3; i++) {
System.out.print("Error! ");
}
System.out.println();
}continue;
}
다음과 같은경우 while(true)를 이용해 무한반복문을 사용했으며
a의 값이 1000이상일경우 Error!메세지가 뜨게하고 continue를 이용해 a변수에 들어갈 값 입력하세요 : 가 다시 뜨도록 했으며a의 값이 100이상 1000이하일 경우 if문으로 조건을 주고 for문을 이용해 Big!이라는 단어가 3번 반복한 후에 break;를 이용해 while반복문이 종료되게 했으며
a의 값이 100이하 if문으로 조건을 주고 for문을 이용해 Small! 이라는 단어가 3번 반복되게하고 break;를 이용해 while반복문이 종료되게 하였음.
'JAVA' 카테고리의 다른 글
6. JAVA 산술 (0) | 2023.07.26 |
---|---|
5. JAVA Scanner2 (0) | 2023.07.26 |
3. JAVA 연산자 (0) | 2023.07.26 |
2. JAVA 자료형 (0) | 2023.07.26 |
1. JAVA 입출력 (0) | 2023.07.26 |