๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- ์๋ฐ๊ธฐ์ด
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ์น๋์๋ณด๋ ์ ์
- ์๋๋ก์ด๋ ์ฑ ๊ฐ๋ฐ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์๋ฐํ๋ก๊ทธ๋๋ฐ
- Streamlit๊ธฐ๋ณธ
- ์๋๋ก์ด๋ ์คํ๋์ค
- ํ๋ค์ค
- MySQL
- Android
- serverless
- ํ์ด์ฌ
- ์คํธ๋ฆผ๋ฆฟ
- Matplotlib ๊ธฐ์ด
- JavaScript
- ์๋ฐ
- Streamlit๊ธฐ์ด
- streamlit
- db
- RESTful API
- ์๋ฐ์ด๋ณด
- ํ๋ค์ค๊ณต๋ถ
- ์๋ฐ๊ณต๋ถ
- ํ์ด์ฌ๊ณต๋ถ
- ์คํธ๋ฆผ๋ฆฟ ๊ธฐ๋ณธ
- ์๋ฐ์คํฌ๋ฆฝํธ ๊ณต๋ถ
- Pandas
- java
- ์น๋์๋ณด๋ ๊ธฐ์ด
Archives
- Today
- Total
ruriruriya
[JAVA] ์๋ฐ์ ๋ฐฐ์ด ๋ณธ๋ฌธ
๋ฐ์ํ
1. ์๋ฐ์ ๋ฐฐ์ด
์๋ฐ์์๋ ๋ฐฐ์ด์ ํ์ฉํด ๋ค๋์ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌํ ์ ์๋ค.
- ๋ฐฐ์ด์ ํญ์ 0๋ถํฐ ์์ํ๋ค. ์ฆ, 0์ด ์ฒซ๋ฒ ์งธ๊ฐ ๋๋ค.
- ๋ฐฐ์ด์ ๊ฐ์ ๋ฐ์ดํฐํ์ผ๋ก๋ง ์ ์ธํ๊ณ ๊ด๋ฆฌํ ์ ์๋ค.
- ๋ฐฐ์ด์ ์ ์ธํ๋ ๋ฐฉ๋ฒ์ 4๊ฐ์ง๋ก ์๋์ ๊ฐ๋ค.
๋ฐฐ์ด ์ ์ธ ํ ๊ฐ์ ๋ณ๊ฒฝ ํ ์ ์๋ค.
public class Main {
public static void main(String[] args) {
//๋ฐฐ์ด ์ ์ธ ์ฒซ๋ฒ ์งธ ๋ฐฉ๋ฒ
String[] coffees01 = new String[4];
coffees01[0] = "์๋ฉ๋ฆฌ์นด๋
ธ";
coffees01[1] = "์นดํ๋ชจ์นด";
coffees01[2] = "๋ผ๋ผ";
coffees01[3] = "์นดํธ์น๋
ธ";
//๋ฐฐ์ด ์ ์ธ ๋๋ฒ ์งธ ๋ฐฉ๋ฒ
String coffee02[] = new String[4];
coffees02[0] = "์๋ฉ๋ฆฌ์นด๋
ธ";
coffees02[1] = "์นดํ๋ชจ์นด";
coffees02[2] = "๋ผ๋ผ";
coffees02[3] = "์นดํธ์น๋
ธ";
//๋ฐฐ์ด ์ ์ธ ์ธ๋ฒ ์งธ ๋ฐฉ๋ฒ
String[] coffees03 = new String[]{"์๋ฉ๋ฆฌ์นด๋
ธ","์นดํ๋ชจ์นด","๋ผ๋ผ","์นดํธ์น๋
ธ"};
//๋ฐฐ์ด ์ ์ธ ๋ค๋ฒ ์งธ ๋ฐฉ๋ฒ
String[] coffes04 = {"์๋ฉ๋ฆฌ์นด๋
ธ","์นดํ๋ชจ์นด","๋ผ๋ผ","์นดํธ์น๋
ธ"};
//๋ฐฐ์ด ํ์ฉ
System.out.println(coffees04[0]+" ํ๋");
System.out.println(coffees04[1]+" ํ๋");
coffees[2] = "์์คํ๋ ์"; // ๊ฐ ๋ณ๊ฒฝ
System.out.println(coffees04[2]+" ํ๋");
System.out.println(coffees04[3]+" ํ๋");
}
}
- ๋ฌธ์์ด ์ธ ๋ค๋ฅธ ์๋ฃํ์ผ๋ก ๋ฐฐ์ด ์ ์ธ ์
public class Main {
public static void main(String[] args) {
int[] i = new int[3];
i[0] = 1;
i[1] = 2;
i[2] = 3;
double[] d = new double[]{20.5.45.5.88.2}; //double ๋ฐ์ดํฐ ์ธ๋ฒ ์งธ ๋ฐฉ๋ฒ์ผ๋ก ๋ฐฐ์ด ์ ์ธ
boolean[] b = {true,false,true}; // boolean ๋ฐ์ดํฐ ๋ค๋ฒ ์งธ ๋ฐฉ๋ฒ์ผ๋ก ๋ฐฐ์ด ์ ์ธ
}
}
2. ๋ฐฐ์ด์ ์ํ
๋ฐฐ์ด์ ๋ฐ์ดํฐ ๊ฐ์ด ๋ง์ ๋ ํ๋ํ๋ ์ค์ ํ์ฌ ์ถ๋ ฅํ๊ธฐ ์ฝ์ง ์๋ค.
๊ทธ๋์ for๋ฌธ์ ํ์ฉํด์ ์ข๋ ํธํ๊ฒ ๋ฐฐ์ด์ ์ฌ์ฉํ ์ ์๋ค.
public class Main {
public static void main(String[] args) {
//for๋ฌธ์ ์ด์ฉํ ๋ฐฐ์ด์ ์ํ
String[] coffees = {"์๋ฉ๋ฆฌ์นด๋
ธ","์นดํ๋ชจ์นด","๋ผ๋ผ","์นดํธ์น๋
ธ"};
for(int t =0;t< coffees.length;t++){ //int i ๋ณ์ ์ ์ธ ํ coffees์ ๊ธธ์ด๋งํผ 1์ฉ ์ฆ๊ฐํ๋ฉฐ ์ถ๋ ฅ
System.out.println(coffees[t] + "ํ๋");
}
System.out.println("์ฃผ๋ฌธ์ด์");
System.out.println();
//enhanced for(for-each) ๋ฐ๋ณต๋ฌธ
for(String coffee : coffees){
System.out.println(coffee+" ํ๋");
}
System.out.println("์ฃผ๋ฌธ์ด์");
}
}
๋ฐ์ํ
'๐ชJava' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ์๋ฐ ๋ฆฌ์คํธ(List)์ ArrayList (0) | 2023.11.13 |
---|---|
[JAVA] ์๋ฐ ์คํธ๋ง๋ฒํผ(StringBuffer) (1) | 2023.11.13 |
[JAVA]์๋ฐ์ ๋ฐ์ดํฐ ํ (1) | 2023.10.16 |
[JAVA] ์๋ฐ ์๋ณ์(Identifier)์ ์์ฝ์ด(Keyword) (0) | 2023.10.16 |
[JAVA] ์๋ฐ ๊ฐ์ผ๋ก ํ๋ ์ผ (1) | 2023.10.04 |