Home ๐Ÿ“’ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ œ์–ด๋ฌธ
Post
Cancel

๐Ÿ“’ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ œ์–ด๋ฌธ



1. ์กฐ๊ฑด๋ฌธ




1-1. if๋ฌธ


if~else๋ฌธ

  • if๋ฌธ์€ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‘ ๋Œ€์˜ ๋ฌธ์žฅ์ค‘์— ํ•˜๋‚˜๊ฐ€ ์ˆ˜ํ–‰๋˜๋Š” ์กฐ๊ฑด๋ฌธ
1
2
3
4
if(์กฐ๊ฑด์‹)
    ์‹คํ–‰ ๋ฌธ์žฅ1;
else
    ์‹คํ–‰ ๋ฌธ์žฅ2;

if ~ else if๋ฌธ

  • if ~ else if๋ฌธ์€ if๋ฌธ์„ ์ด์šฉํ•˜์—ฌ ๋‹ค์ค‘ ์„ ํƒ์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ค€๋‹ค.
1
2
3
4
5
6
7
if(์กฐ๊ฑด์‹1)
    ์‹คํ–‰ ๋ฌธ์žฅ1;
else if(์กฐ๊ฑด์‹2)
    ์‹คํ–‰ ๋ฌธ์žฅ2;
...
else
    ์‹คํ–‰ ๋ฌธ์žฅ3;

์ฒ˜์Œ ์กฐ๊ฑด์‹์ด ์ฐธ์œผ๋กœ ํ‰๊ฐ€๋˜๋ฉด ํ•ด๋‹น ์‹์„ ์ˆ˜ํ–‰ํ•œ ํ›„, if๋ฌธ์žฅ์„ ๋น ์ ธ ๋‚˜๊ฐ€๊ฒŒ ๋œ๋‹ค. ์ฒ˜์Œ ์กฐ๊ฑด์ ˆ์ด ๊ฑฐ์ง“์œผ๋กœ ํ‰๊ฐ€๋˜๋ฉด ๊ณ„์†ํ•ด์„œ else if ์กฐ๊ฑด์ ˆ์„ ํ‰๊ฐ€ํ•˜์—ฌ ์ˆ˜ํ–‰ํ•œ๋‹ค.



1-2. switch


switch ~ case๋ฌธ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
switch(์ˆ˜์‹) {
    case ๊ฐ’1:
        ์‹คํ–‰ ๋ฌธ์žฅ1;
       break;
    case ๊ฐ’2:
         ์‹คํ–‰ ๋ฌธ์žฅ2;
        break;
  .....
   case ๊ฐ’n:
        ์‹คํ–‰ ๋ฌธ์žฅn;
        break;
   defulat:
        ๋””ํดํŠธ ์‹คํ–‰ ๋ฌธ์žฅ;
}

์ค‘์ฒฉ๋œ switch๋ฌธ

1



2. ๋ฐ˜๋ณต๋ฌธ




๋ถ„๊ธฐ๋ฌธ




while๋ฌธ


  • ์‚ฌ์ „ํŒ๋‹จ๋ฐ˜๋ณต
1
while (์ œ์–ด์‹) ๋ช…๋ น๋ฌธ
1
2
3
4
5
6
7
8
9
10
/*
 while ๋ฌธ์œผ๋กœ 1, 2, โ€ฆ, n์˜ ํ•ฉ์„ ๊ตฌํ•จ
 */
  int sum = 0; // ํ•ฉ 
  int i = 1;
  
  while (i <= n) { // i๊ฐ€ n ์ดํ•˜๋ฉด ๋ฐ˜๋ณตํ•จ
  sum += i; // sum์— i๋ฅผ ๋”ํ•จ
  i++; // i๊ฐ’์„ 1๋งŒํผ ์ฆ๊ฐ€์‹œํ‚ด
  }



for ๋ฌธ ๋ฐ˜๋ณต


  • ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ์€ while ๋ฌธ๋ณด๋‹ค for ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Œ
1
for (์ดˆ๊ธฐํ™” ๋ถ€๋ถ„; ์ œ์–ด์‹; ์—…๋ฐ์ดํŠธ ๋ถ€๋ถ„) ๋ช…๋ น๋ฌธ
1
2
3
4
5
6
/* 
for ๋ฌธ์œผ๋กœ 1, 2, โ€ฆ, n์˜ ํ•ฉ์„ ๊ตฌํ•จ
 */
 int sum = 0; // ํ•ฉ 
   for (int i = 1; i <= n; i++)
   sum += i; // sum์— i๋ฅผ ๋”ํ•จ



do


1
2
3
4
5
6
7
8
9
/*
์–‘์ˆ˜๋งŒ ์ž…๋ ฅํ•˜์—ฌ 1, 2, โ€ฆ, n์˜ ํ•ฉ์„ ๊ตฌํ•จ
 */

//n์ด 0๋ณด๋‹ค ํด ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค
 do {
   System.out.print("n๊ฐ’: ");
   n = stdIn.nextInt();
   } while (n <= 0);



if





(์ฐธ๊ณ )



๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์—ฌ๋Ÿฌ๊ธ€๊ณผ ์ฑ… ์ฝ์€ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ •๋ฆฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ข‹์€ ๊ธ€๋กœ ์ €์˜ ๊ณต๋ถ€์— ๋„์›€์„ ์ฃผ์‹œ๋Š” ๋ถ„๋“ค๊ป˜ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

This post is licensed under CC BY 4.0 by the author.

/Database/ DBMS

/Network/ TCP 3 way handshake