Java ๋ฐฐ์ด ๊ฒ ๋ถ
1. ๋ฐฐ์ด ์ ์ฐ๊ณ ํ๋ ํ๋ String ์ฐ๊ธฐ -> ๊ฒ๋ ๊ท์ฐฎ์
String coffeeRoss = "์๋ฉ๋ฆฌ์นด๋
ธ";
String coffeeRachel = "์นดํ๋ชจ์นด";
String coffeeChandler = "๋ผ๋ด";
String coffeeMonica = "์นดํธ์น๋
ธ";
System.out.println(coffeeRoss + "ํ๋"); // ์๋ฉ๋ฆฌ์นด๋
ธ ํ๋
System.out.println(coffeeRachel + "ํ๋");
System.out.println(coffeeChandler + "ํ๋");
System.out.println(coffeeMonica + "ํ๋");
System.out.println("์ฃผ์ธ์");
2. ๋ฐฐ์ด์ ์ ์ธ ๋ฐฉ๋ฒ
// ๋ฐฐ์ด ์ ์ธ ์ฒซ ๋ฒ์งธ ๋ฐฉ๋ฒ (1~3์ ๋์ ๋ฐฐ์ด)
String[] coffees = new String[4];
// ๋ฐฐ์ด ์ ์ธ ๋ ๋ฒ์งธ ๋ฐฉ๋ฒ (๊ดํธ์ ์ด๋ฆ ๋ฐ๊พธ๊ธฐ)
String coffees2[] = new String[4];
coffees[0] = "์๋ฉ๋ฆฌ์นด๋
ธ"; // ์ปดํจํฐ๋ ์ธ๋ฑ์ค ๊ฐ์ ํญ์ 0๋ถํฐ ์์!
coffees[1] = "์นดํ๋ชจ์นด";
coffees[2] = "๋ผ๋ผ";
coffees[3] = "์นดํธ์น๋
ธ";
// ์ธ ๋ฒ์งธ ๋ฐฉ๋ฒ (๋ฐฐ์ด ์ ์ธ๊ณผ ๋์์ ์ด๊ธฐํ)
// ๋๊ดํธ ์์ ์ซ์ ๋ฃ์ผ๋ฉด ์๋ฌ, ์ค๊ดํธ ์์ ์์ ๊ฐ ๋งํผ ๋ฐฐ์ด ์๋ ์์ฑ
String[] coffees3 = new String[] {"์๋ฉ๋ฆฌ์นด๋
ธ", "์นดํ ๋ชจ์นด", "๋ผ๋ผ", "์นดํธ์น๋
ธ"};
// ๋ค ๋ฒ์งธ ๋ฐฉ๋ฒ (์ ์ ๋ฐฐ์ด)
String[] coffees4 = {"์๋ฉ๋ฆฌ์นด๋
ธ", "์นดํ ๋ชจ์นด", "๋ผ๋ผ", "์นดํธ์น๋
ธ" };
3. ๋ฐฐ์ด ์จ์ ์ปคํผ ์ฃผ๋ฌธ (๋ฐฐ์ด ๊ฐ ๋ณ๊ฒฝ ๋ฐฉ๋ฒ)
// ์ปคํผ ์ฃผ๋ฌธ
System.out.println(coffees[0] + " ํ๋");
System.out.println(coffees[1] + " ํ๋");
coffees[2] = "์์คํ๋ ์"; // ๋ฐฐ์ด ๊ฐ ๋ณ๊ฒฝ
System.out.println(coffees[2] + " ํ๋");
System.out.println(coffees[3] + " ํ๋");
4. ๋ค๋ฅธ ์๋ฃํ์ ๋ฐฐ์ด ์ ์ธ ๋ง๋ณด๊ธฐ
// ๋ค๋ฅธ ์๋ฃํ?
int[] i = new int[3];
i[0] = 1;
i[1] = 2;
i[2] = 3;
double d[] = new double[] {0.0,2.4,13.5 };
boolean[] b = {true, true, false};
0