JOO's note

for문 > while문으로 본문

Back-End/알고리즘

for문 > while문으로

pli3452 2015. 1. 8. 12:04

[4-5] 다음의 for문을 while문으로 변경하시오.

[연습문제]/ch4/Exercise4_5.java

public class Exercise4_5 {

public static void main(String[] args) {

for(int i=0; i<=10; i++) {

for(int j=0; j<=i; j++)

System.out.print("*");

System.out.println();

}

} // end of main

} // end of class













[정답]

[연습문제]/ch4/Exercise4_5_2.java

public class Exercise4_5_2 {

public static void main(String[] args) {

int i=0;

while( i<=10) {

int j=0;    // 이때 j값을 0으로 초기화시키는 것에 주의!!

while(j<=i) {

System.out.print("*");

j++;

} System.out.println();

i++;

}

} // end of main

} // end of class

'Back-End > 알고리즘' 카테고리의 다른 글

회문수(palindrome)  (0) 2015.01.08
문자열이 숫자인지 판별  (0) 2015.01.08
피보나치수열  (0) 2015.01.08
문자열이 아닌 숫자에서 각자리의 숫자 뽑아오기  (0) 2015.01.08
charAt(i)와 char의 문자코드값  (0) 2015.01.08
Comments