2023. 1. 25. 10:12ใjava
์ถ๋ ฅ์ ์๋์ ๊ฐ์ด ํ๊ณ ์ถ๋ค๋ฉด
*****
*****
*****
*****
*****
๋จผ์ ์ฒซ์ค *๋ฅผ ๊ฐ๋ก๋ก 5๊ฐ ๋ฐ๋ณตํด์ผ ํจ.
for(int i = 0; i < 5 ; i++) {
System.out.print("*");
}
์ ์ฝ๋๋ฅผ ๋ค์ฏ๋ฒ ๋ฐ๋ณตํด์ผํ๊ธฐ ๋๋ฌธ์ Ctrl+X๋ฅผ ๋๋ฌ ์๋ผ๋ธ๋ค.
๊ทธ๋ฆฌ๊ณ ์ ์ฒด๋ฅผ x๋ก ์ ์ ๋ ํ ๊ทธ x๋ฅผ for๋ฌธ ์์ ๋ฃ์ด์ฃผ๋ ์์ ์ ํ๋ฉด ๋จ. (์ค๋ฌด์์๋ ์ด๋ ๊ฒ ์ฌ์ฉ x )
๋จ์ ์ดํด๋ฅผ ๋๊ธฐ ์ํ ์์
for(int j = 0 ; j < 5 ; j++) {
for(int i = 0; i < 5 ; i++) {
System.out.print("*");
}
System.out.println();
}
๋ฐ๋ณต๋ฌธ ์์ฑํ ํ x๋ฅผ ๋ค์ Ctrl+v๋ก ๋ค์ ์๋ ์ํ๋ก ๋๋ ค์ฃผ๋ฉด ์ดํดํ๊ธฐ ์ฝ๋ค.
์ค์ ์ฝ๋ฉํ ๋๋ ์๋ถํฐ ์ญ ์จ์ผํจ.
j = 0 i = 0 *
i = 1 **
i = 2 ***
:
j = 1 i = 0
i = 1
i = 2
:
j = 2 i = 0
i = 1
i = 2
:
์ด๋ฐ ํํ๋ก ์งํ ๋๋ค.
์ฐ์ต
์๋์ ๊ฐ์ด ์ถ๋ ฅ ํด๋ณด์.
(0,0) (0,1) (0,2)
(1,0) (1,1) (1,2)
(2,0) (2,1) (2,2)
public class ์ด์ค๋ฐ๋ณต๋ฌธ์ฐ์ต {
public static void main(String[] args) {
for(int j = 0 ; j < 3 ; j++) {
for(int i = 0; i < 3 ; i++) {
System.out.print("("+j+","+i+") ");
}
System.out.println();
}
}
}
์ฐ์ต
์ด์ค๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ์ฌ ๊ตฌ๊ตฌ๋จ์ ์ถ๋ ฅํด๋ณด์.
1~9๋ถํฐ ๋ฐ๋ณต
2~9๋ถํฐ ๋ฐ๋ณต
์ด ๋ฐ๋ณต๋ฌธ 2๊ฐ
public class ์ด์ค๋ฐ๋ณต๋ฌธ์ฐ์ต2 {
public static void main(String[] args) {
for(int i = 2 ; i < 10 ; i ++) {
for(int j = 1 ; j < 10 ; j++) {
System.out.println(i + "*" + j + "=" + i * j + " " );
}
System.out.println();
}
}
}
'java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฉ์๋(Method) (0) | 2023.01.25 |
---|---|
์ด์ฐจ์๋ฐฐ์ด (0) | 2023.01.25 |
๋ฐฐ์ด ๋ฌธ์ ํ๊ธฐ (0) | 2023.01.20 |
๋ฐฐ์ด(Array) (0) | 2023.01.20 |
๋ฐ๋ณต๋ฌธ ๋ฌธ์ ํ๊ธฐ2 (0) | 2023.01.19 |