자체임상실험
Inform Restaurant
자체임상실험
전체 방문자
오늘
어제
  • 분류 전체보기 (89)
    • IT정보와 지식 TABLE (1)
      • IT정보 및 꿀팁 (0)
      • Windows (1)
      • Linux (0)
    • Linux TABLE (0)
      • 취약점 점검 스크립트 (0)
    • Developer TABLE (33)
      • Java (33)
      • Java Algorithm (0)
    • DataBase TABLE (1)
      • SQLD-P (1)
    • Cloud TALBE (0)
      • AWS (0)
    • Security TABLE (1)
      • 비박스(bee-box) 취약점 점검 (1)
      • 보안기사 (0)
    • Writer TABLE (42)
      • 기사필사 (42)
      • 서평 (0)
    • Growth TABLE (10)
      • 국민취업지원제도 (4)
      • 국비학원 (6)
    • Life TABLE (0)
      • 자서전 (0)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • 논설위원필사
  • 배열복사
  • 지하공간
  • 초장기 주택담보대출
  • 국비학원
  • 배열
  • array
  • 천자칼럼
  • while
  • 경향신문
  • KH정보교육원
  • 동아일보
  • 조용한 고용
  • 2차원배열
  • do while
  • Java
  • for
  • @
  • if
  • 문자열비교
  • 한겨레
  • 논설위원
  • 반복문
  • 방사능
  • 디엠제트
  • 조건문
  • 해양오염수
  • Switch
  • Arrays
  • 국민취업지원제도

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
자체임상실험

Inform Restaurant

Developer TABLE/Java

반복문 while

2021. 8. 26. 14:00

while 문

  • 조건을 만족시키는 동안 스코프 { }를 반복 수행
  • 반복 횟수를 모를 때 주로 사용
while (조건식) {
	// 조건에 만족할 시 반복 수행
}

 

exit 입력 시 프로그램 종료

public void method2() {
	String sInput = "";
	Scanner s = new Scanner(System.in);
	
	while(sInput.equalsIgnoreCase("exit")) {
		System.out.printf("Insert String: ");
		sInput = s.nextLine();
		
		System.out.println(sInput);
	}
	System.out.println("Bye~!");
}

출력물

Insert String: asdf
asdf
Insert String: EXIT
EXIT
Bye~!

사용자가 입력한 구구단 출력

public void method3() {
	boolean bFlag = true;
	int nDan = 2;
	Scanner s = new Scanner(System.in);

	while(bFlag) {
		int nNum = 1;
		
		System.out.printf("Insert DAN(2~9): ");
		nDan = s.nextInt();
		
		if(2 >= nDan || nDan <= 9) {
			System.out.printf("=== %d 단 ===\n", nDan);
			
			while(nNum <= 9) {
				System.out.printf("%d * %d = %2d\n", nDan, nNum, (nDan * nNum));
				nNum++;
			} 
		} else {
			System.out.println("Are your eyes twisted?\n");
		}
		bFlag = false;
	}
}

출력물

Insert DAN(2~9): 0
Are your eyes twisted?

Insert DAN(2~9): 8
=== 8 단 ===
8 * 1 =  8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72

 

저작자표시 비영리

'Developer TABLE > Java' 카테고리의 다른 글

반복문 do ~ while  (0) 2021.08.26
중첩 for 문  (0) 2021.08.26
반복문 for  (0) 2021.08.26
    'Developer TABLE/Java' 카테고리의 다른 글
    • 난수 생성 Math.random
    • 반복문 do ~ while
    • 중첩 for 문
    • 반복문 for
    자체임상실험
    자체임상실험
    생활에 유용한 정보와 일상을 담은 휴식처, Sobremesa 입니다.

    티스토리툴바