
- ๋ฌธ์ :
- n์ ํจํด๋งํผ "์๋ฐ์๋ฐ์.."๋ฅผ ์ถ๋ ฅํ๋ ๋ฌธ์
- ๋ณ๊ฑฐ ์๋๋ฐ ์ด๋ป๊ฒ ํ์ด์ผํ ์ง ํ์ฐธ ๊ณ ๋ฏผํ๋น
public class proPrac2 {
public static void main(String[] args) {
int n = 5; // n์ ๊ฐ์ ์ ์ฅํ๋ ๋ณ์
String result = ""; // ๊ฒฐ๊ณผ๊ฐ์ ์ถ๋ ฅํ String๋ณ์๋ฅผ ์ ์ธํ๋ค
for (int i = 0; i < n; i++)
// i๋ 0๋ถํฐ n๊น์ง ๋ฐ๋ณต
result += i % 2 == 0 ? "์" : "๋ฐ";
// i๋ฅผ 2๋ก ๋๋ ๋๋จธ์ง๊ฐ 0์ด๋ฉด(์ฐธ์ด๋ฉด), "์" ๊ฑฐ์ง์ด๋ฉด "๋ฐ"
System.out.println(result);
}
}
- ํ์ด
์ด ๋ฌธ์ ๋ ๊ฐ๋จํ๋ ํ์ด๋ ํจ์คํ๋ค.
'๐ Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Programmers] Lv1. ์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2022.11.22 |
|---|---|
| [Programmers] LV1. ์ด์ํ ๋ฌธ์ ๋ง๋ค๊ธฐ (0) | 2022.11.22 |
| [Programmers] LV1. ์์ฃผํ์ง ๋ชปํ ์ ์ (0) | 2022.11.22 |
| [Programmers] LV1. ๋๋์ด ๋จ์ด์ง๋ ์ซ์ ๋ฐฐ์ด (0) | 2022.11.22 |
| [Programmers] LV1. 2016๋ (1) | 2022.11.22 |