์ ๋ณด์ฒ๋ฆฌ
8๊ฐ์ง ๊ธฐ๋ณธํ(Primitive Data types) ๊ณผ ๋ฌด์ํ ๋ง์ ์ฐธ์กฐํ์ด ์๋ค.
๊ธฐ๋ณธํ์ ์ซ์, ๋ฌธ์, ๋ ผ๋ฆฌํ์ด ์๋ค.
์ ์ literal์ ๋ฉ๋ชจ๋ฆฌ์ ๋ก๋๋ ๋ 4๋ฐ์ดํธ๋ก ๋ก๋๋๊ณ ์ค์ literal์ 8๋ฐ์ดํธ๋ก ๋ก๋๋๋ค.
๋ฌด์์์ ์ถ์ถ(์ํ๋ฒณ a๋ถํฐ z์ฌ์ด์ ๋งตํ๋์ด์๋ ์ซ์)ํ์ฌ ๋ฌธ์๋ก ์ถ๋ ฅ
int aa = rd.nextInt(26) + 97;
char c = (char)aa;
System.out.println("๋ฌด์์ ์ํ๋ฒณ" + c + aa);
๋ค๋ฅธ ํํ ๋ฐฉ์
Random rd2 = new Random();
int start = (int) 'a';
int end = (int) 'z';
int rdCh = rd2.nextInt(end-start+1)+start;
char chc = (char)rdCh;
System.out.println("๋ฌด์์ ๋ฌธ์:"+ chc);
์ฝ์ ํํ ๊ฐ: ๋ฌด์์ ์ํ๋ฒณz122
๋ฌด์์ ๋ฌธ์:c
๋ฌด์์ ๋ฌธ์:c
![](https://blog.kakaocdn.net/dn/bH8JXJ/btrNEvYpKX0/Yuy19pl0TCu6DvnReKO9Q0/img.png)
์์ด๋ ๋ก๊ทธ์ธ ๊ตฌํ๊ธฐ
Scanner scan = new Scanner(System.in);
System.out.print("์์ด๋ ์ํธ์
๋ ฅ:");
String line = scan.nextLine(); //์ด์ฉ์๊ฐ ํค๋ณด๋์์ ํ ํ์ ์
๋ ฅ ํ ์ํฐ๋ฅผ ์น๋ฉด ์คํ
//System.out.println("\n์
๋ ฅ๋ ๋ฐ์ดํฐ:" + line);
String[] login = line.split(" "); // split์ด ๋ฐฐ์ด์ ๋ฆฌํด ํ๋ค๊ณ ํ์์ผ๋ ๋ฆฌํด์ ๋ฐ๊ฒ ๋ค. ํด๋์ค๋ฅผ ๋๊ฐ์ด ์ ์ธํ๋ฉด ๋๋ค.
String uid1 = login[0]; //[0] <์์ธ ๋ฒํธ
String pwd = login[1];
System.out.printf("์ด์ฉ์์ ์์ด๋๋ %s ์ด๊ณ ์ด์ฉ์์ ๋น๋ฐ๋ฒํธ๋ %s \n", uid1, pwd);
System.out.println("ํ๋ก๊ทธ๋จ ์ข
๋ฃ");
์ฝ์ ํํ๊ฐ:
์์ด๋ ์ํธ์
๋ ฅ:adfsf 454
์ด์ฉ์์ ์์ด๋๋ adfsf ์ด๊ณ ์ด์ฉ์์ ๋น๋ฐ๋ฒํธ๋ 454
ํ๋ก๊ทธ๋จ ์ข
๋ฃ
Integer.parseInt("5"); //" "๋ก ์ ํ ๋ฌธ์์ด์ " " ๋ฒ๊ฒจ ์ซ์๋ง ๋ํ๋๊ฒ ํด์ค๋ค. (๋ฌธ์ > ์ซ์)
int n1 = Integer.parseInt("5");
int n2 = Integer.parseInt("7");
int sum = n1 + n2;
System.out.println(sum); //์ซ์๋ฅผ ๋ํ๊ธฐ์ 12๊ฐ ๋์ค์ง๋ง ๋ฌธ์์ด "5"๊ณผ"7"๋ฅผ ๋ํ๋ค๋ฉด 57์ด ๋์๋ฒ๋ฆฐ๋ค.
์ฝ์ ํํ๊ฐ: 12
//ํค๋ณด๋์์ 2๊ฐ์ ์ ์๋ฅผ ๋ฐ์๋ค์ฌ์ ๊ณฑ์
์๊ณผ ๊ฒฐ๊ณผ๊ฐ์ ํ์ํ์์ค.
Scanner scan1 = new Scanner(System.in);
System.out.print("์ซ์์
๋ ฅ:");
String input1 = scan1.nextLine();
System.out.print("์ซ์์
๋ ฅ:");
String input2 = scan1.nextLine();
int nn1 = Integer.parseInt(input1);
int nn2 = Integer.parseInt(input2);
System.out.printf("%s * %s = %d \n ", input1, input2, nn1*nn2);
์ฝ์ํํ๊ฐ:
์ซ์์
๋ ฅ:4
์ซ์์
๋ ฅ:5
4 * 5 = 20
ํค๋ณด๋์์ ์์ด๋ ๋น๋ฐ๋ฒํธ ์
๋ ฅ, ์์ด๋๋ smith ์ํธ๋ 0000์ธ ๊ฒฝ์ฐ ๋ก๊ทธ์ธ ์ฑ๊ณต ์๋ ๊ฒฝ์ฐ๋ ๋ก๊ทธ์ธ ์คํจ๋ผ๊ณ ๋ํ๋๊ฒํด๋ผ
Scanner scan2 = new Scanner(System.in);
System.out.print("์์ด๋ ์
๋ ฅ:");
String idid1 = scan2.nextLine();
System.out.print("๋น๋ฐ๋ฒํธ ์
๋ ฅ:");
String pwpw1 = scan2.nextLine();
System.out.printf(idid1.equals("smith") && pwpw1.equals("0000") ? "๋ก๊ทธ์ธ ์ฑ๊ณต" : "๋ก๊ทธ์ธ ์คํจ");
์ฝ์ ๊ฐ:
์์ด๋ ์
๋ ฅ:smith
๋น๋ฐ๋ฒํธ ์
๋ ฅ:0000
๋ก๊ทธ์ธ ์ฑ๊ณต
์์ด๋ ์
๋ ฅ:ใ
ในใดใน
๋น๋ฐ๋ฒํธ ์
๋ ฅ:0000
๋ก๊ทธ์ธ ์คํจ
๋๊ธ