๋ฃจํ๋ฅผ ํ๋ฒ ๋ง ์ฌ์ฉํ ์๋ฐ ๊ตฌ๊ตฌ๋จ ์์ค
์๋ฐ๋ก ๊ตฌ๊ตฌ๋จ ์์ค๋ฅผ ์์ฑํด๋ณด์์ต๋๋ค.
continue, break๋ฌธ์ ์ฌ์ฉํ์ง ์๊ณ , ๋ฃจํ๋ ์ค๋ณต ๋ฃจํ๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ํ๋์ loop๋ฌธ์ ์ฌ์ฉํ ๊ตฌ๊ตฌ๋จ์ ๋๋ค.
Below java source code prints out multiplication table.
It does not use nested-loop. It only uses one for-loop.
public class gugudan {
public static void main(String args[]){
System.out.println("๊ตฌ๊ตฌ๋จ์
๋๋ค.");
int i = 1,b = 1;
while ( i < 10 ) {
if( b == 10 ) {
i+=1;
b=1;
}
if ( i != 10 ) {
System.out.println(i+"*"+b+"="+i*b);
b++;
}
}
}
}
'๐ป Programming > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ Java / ์๋ฐ ] ์์คํ ๋ ๋ฆฝ์ ์ธ ๋ผ์ธ ๊ตฌ๋ถ์ (0) | 2015.04.27 |
---|---|
[ Java / ์๋ฐ ] ํ์ฌ ๋ ์ง ๋ฐ ์๊ฐ ๊ตฌํ๊ธฐ (0) | 2015.04.27 |
[์๊ณ ๋ฆฌ์ฆ/๋ฌธ์ ํ์ด] CodingBat Array-3 fix34 (0) | 2015.04.22 |
[์๊ณ ๋ฆฌ์ฆ/๋ฌธ์ ํ์ด] CodingBat Array-3 maxSpan (0) | 2015.04.22 |
[์๊ณ ๋ฆฌ์ฆ/๋ฌธ์ ํ์ด] CodingBat Logic-2 noTeenSum (0) | 2015.04.22 |