๐Ÿ“˜ [ JAVA ๋ฐ˜๋ณต๋ฌธ ]

rossiebiยท2022๋…„ 12์›” 6์ผ
0

๐Ÿ’ป JAVA ๊ฐœ๋ฐœ์ผ์ง€ย 

๋ชฉ๋ก ๋ณด๊ธฐ
28/38
post-thumbnail

โญ ๋ฐ˜๋ณต๋ฌธ

  • ํ”„๋กœ๊ทธ๋žจ ๋‚ด์—์„œ ๋˜‘๊ฐ™์€ ๋ช…๋ น์„ ์ผ์ • ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•˜์—ฌ ์ˆ˜ํ–‰ํ•˜๋„๋ก ์ œ์–ดํ•˜๋Š” ๋ช…๋ น๋ฌธ

๐Ÿ’ฅ ๋ฐ˜๋ณต๋ฌธ ์ข…๋ฅ˜

  1. while ๋ฌธ
  2. do / while ๋ฌธ
  3. for ๋ฌธ

๐Ÿ’ฅ for๋ฌธ

for (์ดˆ๊ธฐ์‹; ์กฐ๊ฑด์‹; ์ฆ๊ฐ์‹) {

    ์กฐ๊ฑด์‹์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ฐธ์ธ ๋™์•ˆ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ช…๋ น๋ฌธ;

}

๐ŸŒฑ ์˜ˆ์ œ

๐Ÿ’ฅ while๋ฌธ

  • while ๋ฌธ์€ ํŠน์ • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•  ๋•Œ๊นŒ์ง€ ๊ณ„์†ํ•ด์„œ ์ฃผ์–ด์ง„ ๋ช…๋ น๋ฌธ์„ ๋ฐ˜๋ณต ์‹คํ–‰
while (์กฐ๊ฑด์‹) {

    ์กฐ๊ฑด์‹์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ฐธ์ธ ๋™์•ˆ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ช…๋ น๋ฌธ;

}

๐ŸŒฑ ์˜ˆ์ œ

๐Ÿ’ฅ do-while๋ฌธ

  • do / while ๋ฌธ์€ ์กฐ๊ฑด์‹์˜ ๊ฒฐ๊ณผ์™€ ์ƒ๊ด€์—†์ด ๋ฌด์กฐ๊ฑด ํ•œ ๋ฒˆ์€ ๋ฃจํ”„๋ฅผ ์‹คํ–‰
do {

    ์กฐ๊ฑด์‹์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ฐธ์ธ ๋™์•ˆ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ช…๋ น๋ฌธ;

} while (์กฐ๊ฑด์‹);

๐ŸŒฑ ์˜ˆ์ œ

int i = 1, j = 1;

 

while (i < 1) {

    System.out.println("while ๋ฌธ์ด " + i + "๋ฒˆ์งธ ๋ฐ˜๋ณต ์‹คํ–‰์ค‘์ž…๋‹ˆ๋‹ค.");

    i++; // ์ด ๋ถ€๋ถ„์„ ์‚ญ์ œํ•˜๋ฉด ๋ฌดํ•œ ๋ฃจํ”„์— ๋น ์ง€๊ฒŒ ๋จ.

}

System.out.println("while ๋ฌธ์ด ์ข…๋ฃŒ๋œ ํ›„ ๋ณ€์ˆ˜ i์˜ ๊ฐ’์€ " + i + "์ž…๋‹ˆ๋‹ค.");

 

do {

    System.out.println("do / while ๋ฌธ์ด " + i + "๋ฒˆ์งธ ๋ฐ˜๋ณต ์‹คํ–‰์ค‘์ž…๋‹ˆ๋‹ค.");

    j++; // ์ด ๋ถ€๋ถ„์„ ์‚ญ์ œํ•˜๋ฉด ๋ฌดํ•œ ๋ฃจํ”„์— ๋น ์ง€๊ฒŒ ๋จ.

} while (j < 1);

System.out.println("do / while ๋ฌธ์ด ์ข…๋ฃŒ๋œ ํ›„ ๋ณ€์ˆ˜ j์˜ ๊ฐ’์€ " + j + "์ž…๋‹ˆ๋‹ค.");
profile
๋น„์ „๊ณต์ž ๊ฐœ๋ฐœ์ž๋ฅผ ๊ฟˆ๊พธ๋Š” ๋กœ์ง€

0๊ฐœ์˜ ๋Œ“๊ธ€