์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[23] 230131 Java Ch. 2 ๋ณ์์ ํ์ : 3. ํ์ ๋ณํ, 4. ๋ณ์์ ์์คํ ์ ์ถ๋ ฅ [K-๋์งํธ ํธ๋ ์ด๋ 23์ผ] ๋ณธ๋ฌธ
[23] 230131 Java Ch. 2 ๋ณ์์ ํ์ : 3. ํ์ ๋ณํ, 4. ๋ณ์์ ์์คํ ์ ์ถ๋ ฅ [K-๋์งํธ ํธ๋ ์ด๋ 23์ผ]
yjyuwisely 2023. 1. 31. 12:50230131 Tue 23rd class
Ch. 2 ๋ณ์์ ํ์
์ง๋: p. 72 ~ (๊ต์ฌ: ํผ์ ๊ณต๋ถํ๋ ์๋ฐ, ์ ์: ์ ์ฉ๊ถ)
ํผ์ ๊ณต๋ถํ๋ ์๋ฐ
๋ ํ์ผ๋ก ์๋ฐ๋ฅผ ๋ฐฐ์ฐ๋ ์ ๋ฌธ์๊ฐ โ๊ผญ ํ์ํ ๋ด์ฉ์ ์ ๋๋กโ ํ์ตํ ์ ์๋๋ก ๊ตฌ์ฑํ๋ค. โ๋ฌด์์โ โ์ด๋ป๊ฒโ ํ์ตํด์ผ ํ ์ง ์กฐ์ฐจ ๋ชจ๋ฅด๋ ์ ๋ฌธ์์ ๋ง์ฐํ ๋ง์์ ์ดํด, ๊ณผ์ธ ์ ์๋์ด
www.aladin.co.kr
์ค๋ ๋ฐฐ์ด ๊ฒ ์ค ๊ธฐ์ตํ ๊ฒ์ ์ ๋ฆฌํ๋ค.
์ง๋ ์์ ๋ ๋ฐฐ์ด ๊ฒ ์ค ๋ค์ ๊ธฐ์ตํ ๊ฒ
- Widening Casting (automatically) - converting a smaller type to a larger type size
byte โ short โ char โ int โ long โ float โ double
Widening casting is done automatically when passing a smaller size type to a larger size type.
int myInt = 9; double myDouble = myInt; // Automatic casting: int to double System.out.println(myInt); // Outputs 9 System.out.println(myDouble); // Outputs 9.0
- Narrowing Casting (manually) - converting a larger type to a smaller size type
double โ float โ long โ int โ char โ short โ byte
Narrowing casting must be done manually by placing the type in parentheses in front of the value.
double myDouble = 9.78d; int myInt = (int) myDouble; // Manual casting: double to int System.out.println(myDouble); // Outputs 9.78 System.out.println(myInt); // Outputs 9
1) ์๋ ํ์
๋ณํ: ํฐ ํ์
= ์์ ํ์
(์์ ํ์
โ ํฐ ํ์
)
์๋์ผ๋ก ํ์
์ด ๋ณํ๋๋ ๊ฒ
byte byteValue = 10; int intValue = byteValue; //int ํ์
์ด byte ํ์
๋ณด๋ค ํ์ฉ ๋ฒ์๊ฐ ๋ ํฌ๊ธฐ ๋๋ฌธ์ ์๋ ํ์
๋ณํ๋๋ค.
2) ๊ฐ์ ํ์
๋ณํ: ์์ ํ์
= (์์ ํ์
)ํฐ ํ์
(ํฐ ํ์
โ ์์ ํ์
)
๊ฐ์ ๋ก ํ์
์ ๋ณํํ๋ ๊ฒ
ex) short, char์ ๊ฒฝ์ฐ ์ฐ์๊ฐ ์๊ณ ๊ฐ์ ๋ก ํ๋ณํํ๋ค.
int intValue = 10; byte byteValue = (byte) intValue; //int ํ์
์ byte ํ์
๋ณด๋ค ๋ ํฐ ํ์ฉ ๋ฒ์๋ฅผ ๊ฐ์ง๋ฏ๋ก ์๋ ๋ณํ ๋์ง ์๋๋ค. ๊ฐ์ ํ์
๋ณํํ๋ค.
public class OperatorPromotionException2 { public static void main(String[] args) { byte byteValue1 = 10; byte byteValue2 = 20; //byte byteValue3 = byteValue1 + byteValue2; //์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ: ์๋ ํ์
๋ณํ: ํฐ ํ์
= ์์ ํ์
(์์ ํ์
โ ํฐ ํ์
) //byteValue1 + byteValue2๋ int ํ์
์ด๋ค. int byteValue3 = byteValue1 + byteValue2; //๋๋ฒ์งธ ๋ฐฉ๋ฒ: ๊ฐ์ ํ์
๋ณํ: ์์ ํ์
= (์์ ํ์
)ํฐ ํ์
byte byteValue4 = (byte)(byteValue1 + byteValue2); System.out.println(byteValue3); System.out.println(byteValue4); } }
String ํ์ p. 64
์์๋ฐ์ดํ(')๋ก ๊ฐ์ผ ๋ฌธ์๋ char ํ์
๋ณ์์ ์ ์ฅ๋์ด ์ ๋์ฝ๋๋ก ์ ์ฅ๋์ง๋ง,
ํฐ๋ฐ์ดํ(")๋ก ๊ฐ์ผ ๋ฌธ์ ๋๋ ์ฌ๋ฌ ๊ฐ์ ๋ฌธ์๋ค์ ์ ๋์ฝ๋๋ก ๋ฐํ๋์ง ์๋๋ค.
์ฐธ์กฐํ ํ์
์ด๋ค. ๊ธฐ๋ณธํ ํ์
X. String์ด๋ผ๋ ๊ฐ์ฒด๋ก ์ ์ฅํ๋ค.
๊ตฌ๋ถ | 1byte | 2byte | 4byte | 8byte |
์ ์ ํ์ | byte | short char (์ฐ์X, ๋ ๋ค ๊ฐ์ ๋ก ํ๋ณํ) |
int | long |
์ค์ ํ์ | float | double | ||
๋ ผ๋ฆฌ ํ์ | boolean |
๊ธฐ๋ณธ ํ์ ์ ํ์ฉ ๋ฒ์ ํฌ๊ธฐ์์ผ๋ก ์ ๋ฆฌํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
byte < short < int < long < float < double
byte (1) < short (2), char (2) < int (4) < long (8) < float (4, ๋ฒ์ ๋ ํผ) < double (8)
์ ์ ํ์
ํ์ | ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ํฌ๊ธฐ | ์ ์ฅ๋๋ ๊ฐ์ ํ์ฉ ๋ฒ์ | ||
byte | 1 byte | 8 bit | -2^7 ~ (2^7-1) | -128 ~ 127 |
short | 2 byte | 16 bit | -2^15 ~ (2^15-1) | -32,768 ~ 32,767 |
char | 2 byte | 16 bit | 0 ~ (2^16 - 1) | 0 ~ 65535(์ ๋์ฝ๋) |
int | 4 byte | 32 bit | -2^31 ~ (2^31 - 1) | -2,147,483,648 ~ 2,147,483,647 |
long | 8 byte | 64 bit | -2^63 ~ (2^63 - 1) | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
์ค์ ํ์
ํ์ | ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ํฌ๊ธฐ | ์ ์ฅ๋๋ ๊ฐ์ ํ์ฉ ๋ฒ์(์์ ๊ธฐ์ค) | ์ ๋ฐ๋(์์์ ์ดํ ์๋ฆฌ) | |
float | 4byte | 32bit | (1.4*10^-45) ~ (3.4*10^38) | 7์๋ฆฌ |
double | 8byte | 64bit | (4.9*10^-324) ~ (1.8*10^308) | 15์๋ฆฌ |
Ch. 2 ๋ณ์์ ํ์
์ฑ ์ ๋ชฉ์ฐจ
02-1 ๋ณ์
02-2 ๊ธฐ๋ณธ ํ์
02-3 ํ์ ๋ณํ
02-4 ๋ณ์์ ์์คํ ์ ์ถ๋ ฅ
2.3 ํ์ ๋ณํ(type conversion) p. 72
ํ๋์ ํ์
์ ๋ค๋ฅธ ํ์
์ผ๋ก ๋ฐ๊พธ๋ ๊ฒ์ ํ์
๋ณํ(type conversion)์ด๋ผ๊ณ ํ๋ค.
์๋ฐ์์๋ booleanํ์ ์ ์ธํ ๋๋จธ์ง ๊ธฐ๋ณธ ํ์
๊ฐ์ ํ์
๋ณํ์ ์์ ๋กญ๊ฒ ์ํํ ์ ์๋ค.
์๋ฐ์์ ๋ค๋ฅธ ํ์
๋ผ๋ฆฌ์ ์ฐ์ฐ์ ์ฐ์ ํผ์ฐ์ฐ์๋ค์ ๋ชจ๋ ๊ฐ์ ํ์
์ผ๋ก ๋ง๋ ํ์ ์ํ๋๋ค.
๋ฉ๋ชจ๋ฆฌ์ ํ ๋น๋ฐ์ ๋ฐ์ดํธ์ ํฌ๊ธฐ๊ฐ ์๋์ ์ผ๋ก ์์ ํ์
์์ ํฐ ํ์
์ผ๋ก์ ํ์
๋ณํ์ ์๋ตํ ์ ์๋ค.
ํ์ง๋ง ๋ฉ๋ชจ๋ฆฌ์ ํ ๋น๋ฐ์ ๋ฐ์ดํธ์ ํฌ๊ธฐ๊ฐ ํฐ ํ์
์์ ์์ ํ์
์ผ๋ก์ ํ์
๋ณํ์ ๋ฐ์ดํฐ์ ์์ค์ด ๋ฐ์ํ๋ค.
๋ฐ๋ผ์ ์๋์ ์ผ๋ก ๋ฐ์ดํธ์ ํฌ๊ธฐ๊ฐ ์์ ํ์
์ผ๋ก ํ์
๋ณํ์ ํ ๊ฒฝ์ฐ ์๋ฐ ์ปดํ์ผ๋ฌ๋ ์ค๋ฅ๋ฅผ ๋ฐ์์ํจ๋ค.
ํ์
๋ณํ์ด๋ ๋ฐ์ดํฐ ํ์
์ ๋ค๋ฅธ ๋ฐ์ดํฐ ํ์
์ผ๋ก ๋ณํํ๋ ๊ฒ์ ๋งํ๋ค.
* ๋ฐ์ดํฐ ์์ค์ด ์ผ์ด๋๋ฉด ๊ฐ์ ํ๋ณํ์ ํ๋ค.
byte a = 10; //byte ํ์
๋ณ์ a์ 10์ ์ ์ฅ int b = a; //byte ํ์
๋ณ์ a์ ์ ์ฅ๋ 10์ int ํ์
๋ณ์ b์ ๋ณต์ฌํด์ ์ ์ฅ
1) ์๋ ํ์ ๋ณํ (Promotion, implicit conversion) (์์ โ ํฐ)
byte byteValue = 10; int intValue = byteValue; //int ํ์
์ด byte ํ์
๋ณด๋ค ํ์ฉ ๋ฒ์๊ฐ ๋ ํฌ๊ธฐ ๋๋ฌธ์ ์๋ ํ์
๋ณํ๋๋ค.
์๋์ผ๋ก ํ์
๋ณํ์ด ์ผ์ด๋๋ ๊ฒ์ ์๋ฏธํ๋ค.
์๋ ํ์
๋ณํ์ ํ๋ก๊ทธ๋จ ์คํ ๋์ค์ ๊ฐ์ ํ์ฉ ๋ฒ์๊ฐ ์์ ํ์
์ด ํ์ฉ ๋ฒ์๊ฐ ํฐ ํ์
์ผ๋ก ์ ์ฅ๋ ๋ ๋ฐ์ํ๋ค.
ํฐ ํ์
= ์์ ํ์
๊ดํธ๋ ์๋ต ๊ฐ๋ฅํ๋ค.
๊ธฐ๋ณธ ํ์
์ ํ์ฉ ๋ฒ์ ํฌ๊ธฐ์์ผ๋ก ์ ๋ฆฌํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
byte < short < int < long < float < double
์์ )
public class PromotionExample { public static void main(String[] args) { byte byteValue = 10; //int //int(4) <- byte(1) int intValue = byteValue; System.out.println("intValue : "+intValue); char charValue = '๊ฐ'; //int(4) <- char(2) intValue = charValue; System.out.println("๊ฐ์ ์ ๋์ฝ๋ : "+intValue); intValue = 50; //long(8) <- int(4) long longValue = intValue; System.out.println("longValue : "+longValue); longValue = 100; //float(4) <- int(4) float floatValue = longValue; System.out.println("floatValue : "+floatValue); //๊ฐ์ ํ๋ณํ ๋ฌธ๋ฒ intValue = (int)floatValue; floatValue = 100.5F; //double(8) <- float(4) double doubleValue = floatValue; System.out.println("doubleValue: "+doubleValue); } }
๊ฒฐ๊ณผ)
int ์ ์๋ง ํํ
float ์ ์, ์์์ ๋ ๋ค ํํ. ๋ ํฌ๋ค.
float(4) <- int(4)๋ก ๊ฐ์ ํ๋ณํ๋๋ค.
intValue : 10 ๊ฐ์ ์ ๋์ฝ๋ : 44032 longValue : 50 floatValue : 100.0 doubleValue: 100.5
2) ๊ฐ์ ํ์ ๋ณํ (Casting, explicit conversion) (ํฐ โ ์์)
ํฐ ํ์ฉ ๋ฒ์ ํ์
์ ์์ ํ์ฉ ๋ฒ์ ํ์
์ผ๋ก ๊ฐ์ ๋ก ๋๋ ์ ์ ์ฅํ๋ ๊ฒ
์์ ํ์
= (์์ ํ์
)ํฐ ํ์
์บ์คํ
์ฐ์ฐ์ ๊ดํธ (๋๋๋ ๋จ์)๋ฅผ ์ฌ์ฉํ๋ค. ์๋ฐ์์๋ ์ด ๊ดํธ๋ฅผ ํ์
์บ์คํธ(type cast) ์ฐ์ฐ์๋ผ๊ณ ํ๋ค.
int intValue = 10; byte byteValue = (byte) intValue; //int ํ์
์ byte ํ์
๋ณด๋ค ๋ ํฐ ํ์ฉ ๋ฒ์๋ฅผ ๊ฐ์ง๋ฏ๋ก ์๋ ๋ณํ ๋์ง ์๋๋ค. ๊ฐ์ ํ์
๋ณํํ๋ค.
int ํ์ ์ byte ํ์ ๋ณด๋ค ๋ ํฐ ํ์ฉ ๋ฒ์๋ฅผ ๊ฐ์ง๋ค. ๋ฐ๋ผ์ int ํ์ ์ byte ํ์ ์ผ๋ก ์๋ ๋ณํ ๋์ง ์๋๋ค. ํ์ง๋ง (byte) ์บ์คํ ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํด์ byte ํ์ ์ผ๋ก ๊ฐ์ ๋ณํํ ์ ์๋ค.
์์ )
public class CastingExample { public static void main(String[] args) { int intValue = 44032; // char(2) <- int(4): ๊ฐ์ ํ ๋ณํ char charValue = (char) intValue; System.out.println("charValue : "+charValue); long longValue = 500; // int(4) <- long(8): ๊ฐ์ ํ ๋ณํ intValue = (int) longValue; System.out.println("intValue : "+intValue); double doubleValue = 3.14; // int(4) <- double(8): ๊ฐ์ ํ ๋ณํ intValue = (int) doubleValue; System.out.println("intValue : "+intValue); } }
๊ฒฐ๊ณผ)
charValue : ๊ฐ intValue : 500 intValue : 3
3) ์ ์ ์ฐ์ฐ์์์ ์๋ ํ์ ๋ณํ p. 76
์ ์ ํ์
๋ณ์๊ฐ ์ฐ์ ์ฐ์ฐ์์์ ํผ์ฐ์ฐ์๋ก ์ฌ์ฉํ๋ฉด
int ํ์
๋ณด๋ค ์์ byte, short ํ์
์ ๋ณ์๋ int ํ์
์ผ๋ก ์๋ ํ์
๋ณํ๋์ด ์ฐ์ฐ์ ์ํํ๋ค.
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
public class ByteOperationExample { public static void main(String[] args) { //byte result = (byte)(x+y); ์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ byte x = 10; byte y = 20; byte result2 = (byte)(x+y); System.out.println(result2); //๋๋ฒ์งธ ๋ฐฉ๋ฒ int result1 = x + y; System.out.println(result1); } }
์์ ) ์ ์ ํ์ ์ ์ฐ์ฐ
public class LongOperationExample { public static void main(String[] args) { byte value1 = 10; int value2 = 100; long value3 = 1000L; // byte + int + long // int + int + long // long + long + long( long result = value1 + value2 + value3; System.out.println(result); } }
๊ฒฐ๊ณผ)
1110
4) ์ค์ ์ฐ์ฐ์์์ ์๋ ํ์ ๋ณํ p. 78
์ค์ ํ์
๋ณ์๊ฐ ์ฐ์ ์ฐ์ฐ์์์ ํผ์ฐ์ฐ์๋ก ์ฌ์ฉ๋ ๊ฒฝ์ฐ ๋ ํผ์ฐ์ฐ์๊ฐ ๋์ผํ ํ์
์ด๋ผ๋ฉด ํด๋น ํ์
์ผ๋ก ์ฐ์ฐ๋์ง๋ง,
ํผ์ฐ์ฐ์ ์ค ํ๋๊ฐ double ํ์
์ด๋ผ๋ฉด ๋ค๋ฅธ ํผ์ฐ์ฐ์๋ double ํ์
์ผ๋ก ์๋ ํ์
๋ณํ๋์ด ์ฐ์ฐ์ ์ํํ๋ค. ๋ฐ๋ผ์ ์ฐ์ฐ ๊ฒฐ๊ณผ๋ double ํ์
์ด ๋๋ค.
int ํ์
๊ณผ double ํ์
์ ์ฐ์ฐํด๋ ๋์ผํ ๊ณผ์ ์ ๊ฑฐ์น๋ค. ๋จผ์ int ํ์
์ ํผ์ฐ์ฐ์๊ฐ double ํ์
์ผ๋ก ์๋ ๋ณํ๋๊ณ ์ฐ์ฐ์ ์ํํ๋ค.
int intValue = 10; double doubleValue = 5.5; double result = intValue + doubleValue; //intValue๋ double๊ฐ์ผ๋ก ๋ณํํ๋ค. result = 15.5
๋ง์ฝ ๊ผญ int ํ์ ์ผ๋ก ์ฐ์ฐ์ ํด์ผ ํ๋ค๋ฉด double ํ์ ์ int ํ์ ์ผ๋ก ๊ฐ์ ๋ณํํ๊ณ ๋ง์ ์ฐ์ฐ์ ํ๋ฉด ๋๋ค.
int intValue = 10; double doubleValue = 5.5; int result = intValue + (int) doubleValue; //result = 15
์์ )
public class OperatorPromotionException { public static void main(String[] args) { // ์ค์ + ์ค์ double result1 = 1.2f + 3.4; // ์ ์ + ์ค์ // ์ค์ + ์ค์ // 10.0+5.5 double result2 = 10 + 5.5; //๊ฐ์ ํ๋ณํ (double -> int) int result3 = (int)(10 + 5.5); System.out.println("result1: "+result1); System.out.println("result2: "+result2); System.out.println("result3: "+result3); } }
๊ฒฐ๊ณผ)
result1: 4.600000047683716 result2: 15.5 result3: 15
์์ 2) p.81
public class OperatorPromotionException2 { public static void main(String[] args) { byte byteValue1 = 10; byte byteValue2 = 20; //byte byteValue3 = byteValue1 + byteValue2; //์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ: ์๋ ํ์
๋ณํ: ํฐ ํ์
= ์์ ํ์
(์์ ํ์
โ ํฐ ํ์
) //byteValue1 + byteValue2๋ int ํ์
์ด๋ค. int byteValue3 = byteValue1 + byteValue2; //๋๋ฒ์งธ ๋ฐฉ๋ฒ: ๊ฐ์ ํ์
๋ณํ: ์์ ํ์
= (์์ ํ์
)ํฐ ํ์
byte byteValue4 = (byte)(byteValue1 + byteValue2); System.out.println(byteValue3); System.out.println(byteValue4); } }
๊ฒฐ๊ณผ)
30 30
์์ 3)
char charValue1 = 'A'; char charValue2 = '1'; //์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ: ์๋ ํ์
๋ณํ: ํฐ ํ์
= ์์ ํ์
(์์ ํ์
โ ํฐ ํ์
) //char charValue3 = charValue1 + charValue2; int intValue2 = charValue1 + charValue2; System.out.println(intValue2); //๋๋ฒ์งธ ๋ฐฉ๋ฒ: ๊ฐ์ ํ์
๋ณํ: ์์ ํ์
= (์์ ํ์
)ํฐ ํ์
char charValue3 = (char)(charValue1 + charValue2); System.out.println(charValue3);
๊ฒฐ๊ณผ)
114 r
์์ 4) int๋ ์์์ ์ ์ ์ฅํ๋ ๊ณต๊ฐ์ด ์๋ค. ์์์ ์ ๋ฒ๋ ค์ง๋ค.
int intValue3 = 10; int intValue4 = intValue3/4; System.out.println(intValue4); double intValue5 = intValue3/4; System.out.println(intValue5);
๊ฒฐ๊ณผ)
2 2.0
์์ 5)
int x = 1; int y = 2; double result = (double)x/y; System.out.println(result);
๊ฒฐ๊ณผ)
0.5
5) + ์ฐ์ฐ์์์ ๋ฌธ์์ด ์๋ ํ์ ๋ณํ p. 82
1. ํผ์ฐ์ฐ์๊ฐ ๋ชจ๋ ์ซ์์ผ ๊ฒฝ์ฐ: ๋ง์
์ฐ์ฐ ์ํํ๋ค.
2. ํผ์ฐ์ฐ์ ์ค ํ๋๊ฐ ๋ฌธ์์ด์ผ ๊ฒฝ์ฐ: ๋๋จธ์ง ํผ์ฐ์ฐ์๋ ๋ฌธ์์ด๋ก ์๋ ๋ณํ๋์ด ๋ฌธ์์ด ๊ฒฐํฉ ์ฐ์ฐ์ ์ํํ๋ค.
๋จผ์ ์ํ๋ ์ฐ์ฐ์ด ๋ง์
์ฐ์ฐ์ด๋ผ๋ฉด ๋ง์
๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ง๊ณ ๊ทธ๋ค์ + ์ฐ์ฐ์ ์ํํ๋ค.
String str = 1 + 2 + "3"; String str = 3 + "3"; String str = 33;
์์์๋ถํฐ ์์ฐจ์ ์ผ๋ก + ์ฐ์ฐ์ ์ํํ์ง ์๊ณ ์ฐ์ ์ฐ์ฐํ๊ณ ์ถ์ ๋ถ๋ถ์ด ์๋ค๋ฉด ํด๋น ๋ถ๋ถ์ ๊ดํธ ()๋ก ๊ฐ์ธ์ค๋ค. ๊ดํธ๋ ์ต์ฐ์ ์ผ๋ก ์ฐ์ฐ์ ์ํํ๋ค.
์์ ) CONCATENATE(์ฐ์์ํค๋ค)ํจ์๋ ์ฌ๋ฌ ๊ฐ์ ๋ฒ์ ๋๋ ์ฌ๋ฌ๊ฐ์ ํ
์คํธ ๋ฌธ์์ด์ ํ๋์ ํ
์คํธ ๋ฌธ์์ด๋ก ์ฐ๊ฒฐํ๋ ํจ์์
๋๋ค.
The concat() method appends (concatenate) a string to the end of another string.
public class StringConcatExample { public static void main(String[] args) { //์ซ์ ์ฐ์ฐ // ์ซ์ + ์ซ์ + ์ซ์ int value = 10 + 2 + 8; System.out.println("value: " + value); //๋ฌธ์์ด ๊ฒฐํฉ ์ฐ์ฐ์(+) // ์ซ์ + ์ซ์ + ๋ฌธ์์ด // 10 + 2(12) // 12+"8"์ด๊ณ , ๋ค๊ฐ ๋ฌธ์์ด์ด๋ฏ๋ก +์ฐ์ฐ์๋ ๋ ๊ฐ์ ๊ฐ์ ์ฐ๊ฒฐ์ํจ๋ค. // 128 String str1 = 10 + 2 + "8"; System.out.println("str1: " + str1); } }
๊ฒฐ๊ณผ)
value: 20 str1: 128
6) ๋ฌธ์์ด์ ๊ธฐ๋ณธ ํ์ ์ผ๋ก ๊ฐ์ ํ์ ๋ณํ p. 83
String: ๊ธฐ๋ณธํ ํ์ ์ด ์๋๋ค. ์ฐธ์กฐํ ํ์ ์ด๋ค. String์ด๋ผ๋ ๊ฐ์ฒด๋ก ์ ์ฅํ๋ค.
ex) "12"์ "3.5"๋ฅผ ์ ์ ๋ฐ ์ค์ ํ์ ์ผ๋ก ๋ณํํด์ ์ซ์ ์ฐ์ฐ์ ํ๋ค.
๋ณํ ํ์ | ์ฌ์ฉ ์ |
String โ byte | String str = "10"; byte value = Byte.parseByte(str); |
String โ short | String str = "200"; short value = Short.parseShort(str); |
String โ int | String str = "300000"; int value = Integer.parseInt(str); |
String โ long | String str = "40000000000'; long value = Long.parseLong(str); |
String โ float | String str = "12.345"; float value = Float.parseFloat(str); |
String โ double | String str = "12.345"; double value = Double.parseDouble(str); |
String โ boolean | String str = "true"; boolean value = Boolean.parseBoolean(str); |
๊ธฐ๋ณธ ํ์ (byte, short, char, int, long, float, double, boolean)์ ๊ฐ์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ์๋ ๊ฐ๋จํ String.valueOf() ๋ฉ์๋๋ฅผ ์ด์ฉํ๋ค.
String str = String.valueOf(๊ธฐ๋ณธํ์
๊ฐ);
ex) ๋ฌธ์์ด "3"์ ์ป์ ์ ์๋ค.
String.valueOf(3)
์์ )
public class PrimitiveAndStringConversionExample { public static void main(String[] args) { //String -> int int value1 = Integer.parseInt("10"); //String -> double double value2 = Double.parseDouble("3.14"); //String -> boolean boolean value3 = Boolean.parseBoolean("true"); System.out.println("value1: " + value1); System.out.println("value2: " + value2); System.out.println("value3: " + value3); //int -> String String str1 = String.valueOf(10); //double -> String String str2 = String.valueOf(3.14); //boolean -> String String str3 = String.valueOf(true); System.out.println("str1: " + str1); System.out.println("str2: " + str2); System.out.println("str3: " + str3); } }
๊ฒฐ๊ณผ)
value1: 10 value2: 3.14 value3: true str1: 10 str2: 3.14 str3: true
charAt์ด๋ string ํ์
์ผ๋ก ๋ฐ์ ๋ฌธ์์ด์ char ํ์
์ผ๋ก ํ ๊ธ์๋ง ๋ฐ๋ ํจ์์ด๋ค.
char var4 = strValue.charAt(0); //0: ์ธ๋ฑ์ค ๋ฒํธ
๋ฐ์ดํฐ ์์ค์ ๋ง๊ธฐ ์ํด ์์ ํ์ โ ํฐ ํ์ ์ผ๋ก ๊ฐ๋ค.
๋ง๋ฌด๋ฆฌ p. 85
1) ์๋ ํ์
๋ณํ: ํฐ ํ์
= ์์ ํ์
(์์ ํ์
โ ํฐ ํ์
)
์๋์ผ๋ก ํ์
์ด ๋ณํ๋๋ ๊ฒ
byte byteValue = 10; int intValue = byteValue; //int ํ์
์ด byte ํ์
๋ณด๋ค ํ์ฉ ๋ฒ์๊ฐ ๋ ํฌ๊ธฐ ๋๋ฌธ์ ์๋ ํ์
๋ณํ๋๋ค.
2) ๊ฐ์ ํ์ ๋ณํ: ์์ ํ์ = (์์ ํ์ )ํฐ ํ์ (ํฐ ํ์ โ ์์ ํ์ )
int intValue = 10; byte byteValue = (byte) intValue; //int ํ์
์ byte ํ์
๋ณด๋ค ๋ ํฐ ํ์ฉ ๋ฒ์๋ฅผ ๊ฐ์ง๋ฏ๋ก ์๋ ๋ณํ ๋์ง ์๋๋ค. ๊ฐ์ ํ์
๋ณํํ๋ค.
๊ฐ์ ๋ก ํ์
์ ๋ณํํ๋ ๊ฒ
ex) short, char์ ๊ฒฝ์ฐ ์ฐ์๊ฐ ์๊ณ ๊ฐ์ ๋ก ํ๋ณํํ๋ค.
3) ๋ฌธ์์ด ๊ฒฐํฉ ์ฐ์ฐ: ๋ฌธ์์ด๊ณผ + ์ฐ์ฐ์ ํ๋ฉด ๋ค๋ฅธ ํผ์ฐ์ฐ์๋ ๋ฌธ์์ด๋ก ๋ณํ๋์ด ๋ฌธ์์ด ๊ฒฐํฉ์ด ์ผ์ด๋๋ค.
4) Integer.parseInt(): ๋ฌธ์์ด์ ์ ์ int ํ์ ์ผ๋ก ๋ณํํ๋ค.
5) Double.parseDouble(): ๋ฌธ์์ด์ ์ค์ double ํ์ ์ผ๋ก ๋ณํํ๋ค.
2.4 ๋ณ์์ ์์คํ ์ ์ถ๋ ฅ p. 89
ํ์ค ์ถ๋ ฅ ์ฅ์น๋ ๋ชจ๋ํฐ์ด๊ณ , ํ์ค ์
๋ ฅ ์ฅ์น๋ ํค๋ณด๋์ด๋ค.
๋ณ์์ ์ ์ฅ๋ ๊ฐ์ ๋ชจ๋ํฐ๋ก ์ถ๋ ฅํ๋ ๋ฐฉ๋ฒ๊ณผ ํค๋ณด๋๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ ๋ณ์์ ์ ์ฅํ๋ ๋ฐฉ๋ฒ์ ์์๋ณธ๋ค.
System.out์ ์์คํ
์ ํ์ค ์ถ๋ ฅ ์ฅ์น๋ฅผ ๋งํ๋ค. in์ ํ์ค ์
๋ ฅ ์ฅ์น์ด๋ค.
System.in.read();
1) ๋ชจ๋ํฐ๋ก ๋ณ์ซ๊ฐ ์ถ๋ ฅํ๊ธฐ
System. + out. + println(๋ฆฌํฐ๋ด ๋๋ ๋ณ์);
System: ์์คํ
์ด ๊ฐ์ง๊ณ ์๋
out: ์ถ๋ ฅ ์ฅ์น๋ก
println(๋ฆฌํฐ๋ด ๋๋ ๋ณ์): ๊ดํธ ์์ ๋ด์ฉ์ ์ถ๋ ฅํ๊ณ ํ์ ๋ฐ๊พผ๋ค.
printf("ํ์๋ฌธ์์ด",๊ฐ1,๊ฐ2,...);
๊ดํธ ์์ ์ฒซ ๋ฒ์งธ ๋ฌธ์์ด ํ์๋๋ก ๋ด์ฉ์ ์ถ๋ ฅํ๋ค.
%[$argument_index$][flags][width][.precision][conversion]
%: ํ์ ๋ฌธ์์ด์ ์์
[$argument_index$]: ๊ฐ์ ์๋ฒ ex) 1$๋ ์ฒซ ๋ฒ์งธ ๊ฐ, 2$๋ ๋ ๋ฒ์งธ ๊ฐ์ ๋ปํ๋ค.
[flags]: -, o: ๋น์๋ฆฌ๋ฅผ ์ฑ์ฐ๋ ๋ฐฉ๋ฒ์ธ๋ฐ ์๋ต๋๋ฉด ์ผ์ชฝ์ด ๊ณต๋ฐฑ์ผ๋ก ์ฑ์์ง๊ณ , -๊ฐ ์ค๋ฉด ์ค๋ฅธ์ชฝ์ด ๊ณต๋ฐฑ์ผ๋ก ์ฑ์์ง๋ค. 0์ ๊ณต๋ฐฑ ๋์ 0์ผ๋ก ์ฑ์ด๋ค.
[width]: ์ ์ฒด ์๋ฆฟ์
[.precision]: ์์ ์๋ฆฟ์
[conversion]: ๋ณํ ๋ฌธ์, ์ ๊ณต๋๋ ๊ฐ์ ํ์
์ ๋ฐ๋ผ d(์ ์), f(์ค์), s(๋ฌธ์์ด)์ ์
๋ ฅํ๋ค.
ํ์ ๋ฌธ์์ด์์ %์ conversion(๋ณํ ๋ฌธ์)์ ํ์๋ก ์์ฑํ๊ณ ๊ทธ ์ธ์ ํญ๋ชฉ์ ๋ชจ๋ ์๋ตํ ์ ์๋ค.
์์ฃผ ์ฌ์ฉ๋๋ ํ์ ๋ฌธ์์ด
์ค์: %์ ์ฒด๊ธธ์ด.์์์ ์ด ๋์ค๋ ๊ฐ์
ํ์ํ๋ ๋ฌธ์์ด | ์ค๋ช | ์ถ๋ ฅ ํํ | |
์ ์ | %d | ์ ์ | 123 |
%6d | 6์๋ฆฌ ์ ์, ์ผ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | ___123 | |
%-6d | 6์๋ฆฌ ์ ์, ์ค๋ฅธ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | 123___ | |
%06d | 6์๋ฆฌ ์ ์, ์ผ์ชฝ ๋น ์๋ฆฌ 0 ์ฑ์ | 000123 | |
์ค์ | %10.2f | ์์์ ์ด์ 7์๋ฆฌ, ์์์ ์ดํ 2์๋ฆฌ, ์ผ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | ___123.45 |
%-10.2f | ์์์ ์ด์ 7์๋ฆฌ, ์์์ ์ดํ 2์๋ฆฌ, ์ค๋ฅธ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | 123.45___ | |
%010.2f | ์์์ ์ด์ 7์๋ฆฌ, ์์์ ์ดํ 2์๋ฆฌ, ์ผ์ชฝ ๋น ์๋ฆฌ 0์ฑ์ | 0000123.45 | |
๋ฌธ์์ด | %s | ๋ฌธ์์ด | abc |
%6s | 6์๋ฆฌ ๋ฌธ์์ด, ์ผ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | ___abc | |
%-6s | 6์๋ฆฌ ๋ฌธ์์ด, ์ค๋ฅธ์ชฝ ๋น ์๋ฆฌ ๊ณต๋ฐฑ | abc___ | |
ํน์๋ฌธ์ | \t | ํญ(tab) | |
\n | ์ค๋ฐ๊ฟ | ||
%% | % | % |
์์ ) p. 91
public class P90PrintExample { public static void main(String[] args) { int value = 123; System.out.println("์ํ์ ๊ฐ๊ฒฉ: "+value+"์"); // printf("ํ์๋ฌธ์์ด",๊ฐ) System.out.printf("์ํ์ ๊ฐ๊ฒฉ:%d\n์", value); System.out.printf("์ํ์ ๊ฐ๊ฒฉ:%6d\n์", value); System.out.printf("์ํ์ ๊ฐ๊ฒฉ:%-6d\n์", value); System.out.printf("์ํ์ ๊ฐ๊ฒฉ:%06d\n์", value); double area = 3.14 * 10 * 10; System.out.printf("๋ฐ์ง๋ฆ์ด %d์ธ ์์ ๋์ด: %10.2f\n",10,area); String name = "ํ๊ธธ๋"; String job = "๋์ "; System.out.printf("%6d | %-10s | %10s\n", 1, name, job); } }
๊ฒฐ๊ณผ)
์ํ์ ๊ฐ๊ฒฉ: 123์ ์ํ์ ๊ฐ๊ฒฉ:123 ์์ํ์ ๊ฐ๊ฒฉ: 123 ์์ํ์ ๊ฐ๊ฒฉ:123 ์์ํ์ ๊ฐ๊ฒฉ:000123 ์๋ฐ์ง๋ฆ์ด 10์ธ ์์ ๋์ด: 314.00 1 | ํ๊ธธ๋ | ๋์
2) ํค๋ณด๋์์ ์ ๋ ฅ๋ ๋ด์ฉ์ ๋ณ์์ ์ ์ฅํ๊ธฐ p. 92
ํค๋ณด๋์์ ํค ํ๋๋ฅผ ์
๋ ฅํ๋ฉด ํ๋ก๊ทธ๋จ์์๋ ์ซ์๋ก ๋ ํค์ฝ๋๋ฅผ ์ฝ์ ์ ์๋ค.
ex) a = 97๋ฒ, 1 = 49๋ฒ
int keyCode = System. + in. + read();
System: ์์คํ
์ด ๊ฐ์ง๊ณ ์๋
in: ์
๋ ฅ ์ฅ์น์์
read: ์
๋ ฅ๋ ํค์ฝ๋๋ฅผ ์ฝ์ด๋ผ.
keyCode: ์ฝ์ ํค์ฝ๋๋ฅผ ๋ณ์์ ์ ์ฅํ๋ค.
์์ )
public class P93KeyCodeExample { public static void main(String[] args) throws Exception { int keyCode; keyCode=System.in.read(); System.out.println("keyCode: " + keyCode); keyCode=System.in.read(); System.out.println("keyCode: " + keyCode); keyCode=System.in.read(); System.out.println("keyCode: " + keyCode); } }
๊ฒฐ๊ณผ) 97: [A]ํค์ ๋ํ ํค์ฝ๋
[Enter]ํค๋ ๋ค๋ฅธ ํค์ ๋ค๋ฅด๊ฒ ์บ๋ฆฌ์ง ๋ฆฌํด(CR: 13)+๋ผ์ธ ํผํธ(LF: 10) ํค์ฝ๋ ๊ตฌ์ฑ
A carriage return, sometimes known as a cartridge return and often shortened to CR, <CR> or return, is a control character or mechanism used to reset a device's position to the beginning of a line of text.
a keyCode: 97 keyCode: 13 keyCode: 10
์์ ) System.in.read()๋ก ์ฝ์๊ธฐ ๋๋ฌธ์ int ํ์ ์ ํค์ฝ๋๋ฅผ ์ป๋๋ค.
public class P94ContinueKeyCodeReadExample { public static void main(String[] args) throws Exception { int keyCode; while(true) { //๋ฌดํ๋๋ก ํค๋ณด๋๋ก ์
๋ ฅ keyCode = System.in.read(); System.out.println("keyCode : "+keyCode); //๋ง์ฝ์ ์ฌ์ฉ์๊ฐ q๋ฅผ ์
๋ ฅํ๋ฉด if(keyCode==113) { // ๋ฐ๋ณต๋ฌธ์ ์ข
๋ฃํ๋ค. break; } System.out.println("์ข
๋ฃ"); } } }
๊ฒฐ๊ณผ)
q keyCode : 113
Scanner ํด๋์ค p. 95
System.in.read()์ ๋จ์ ์ ํค์ฝ๋๋ฅผ ํ๋์ฉ ์ฝ๊ธฐ ๋๋ฌธ์ 2๊ฐ ์ด์์ ํค๊ฐ ์กฐํฉ๋ ํ๊ธ์ ์ฝ์ ์ ์๋ค.
๊ทธ๋ฆฌ๊ณ ํค๋ณด๋๋ก๋ถํฐ ์
๋ ฅ๋ ํต ๋ฌธ์์ด๋ก ์ฝ์ง ๋ชปํ๋ค.
์ด๋ฌํ ๋จ์ ์ ๋ณด์ํ๊ธฐ ์ํด ์๋ฐ๋ Scanner ํด๋์ค๋ฅผ ์ ๊ณตํ๊ณ ์๋ค.
Scanner scanner = new Scanner(System.in);
Scanner scanner: Scanner ํ์
์ ๋ณ์ scanner์ ์ ์ธํ๋ค.
new Scanner(System.in): ์์คํ
์ ์
๋ ฅ ์ฅ์น๋ก๋ถํฐ ์ฝ๋ Scanner ์์ฑํ๋ค.
System: ์์คํ
์ด ๊ฐ์ง๊ณ ์๋
in: ์
๋ ฅ ์ฅ์น์์
new Scanner: ์์ฑ๋ Scanner๋ฅผ ๋ณ์์ ์ ์ฅํ๋ค.
String inputData = scanner.nextLine();
String inputDate: ๋ณ์ ์ ์ธ
scanner.nextLine(): [Enter]ํค๊ฐ ์
๋ ฅ๋๊ธฐ ์ ๊น์ง ๋๊ธฐ ์ํ๊ฐ ๋๋ฉฐ, [Enter]ํค๊ฐ ์
๋ ฅ๋๋ฉด ์
๋ ฅ๋ ๋ชจ๋ ๋ด์ฉ์ ๋ฌธ์์ด๋ก ์ฝ๋๋ค.
scanner: ์ฝ์ ๋ฌธ์์ด์ String ๋ณ์์ ์ ์ฅํ๋ค.
์์ ) scanner.nextLine()์ผ๋ก ์ฝ์๊ธฐ ๋๋ฌธ์ String ํ์ ์ ๋ฌธ์์ด์ ์ป๋๋ค.
import java.util.Scanner; //Scanner๊ฐ java.util ํจํค์ง์ ์๋ค๋ ๊ฒ์ ์ปดํ์ผ๋ฌ์๊ฒ ์๋ ค์ค๋ค. public class P96_ScannerExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String inputData; while(true) { inputData=scanner.nextLine();//์ปค์๊ฐ ๊น๋นก์ธ๋ค. System.out.println("์
๋ ฅ๋ ๋ฌธ์์ด: \""+inputData+"\""); //๋ง์ฝ์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๊ฐ์ด q์ด๋ฉด if(inputData.equals("q")) { //๋ฐ๋ณต๋ฌธ์ ์ข
๋ฃํ๋ค. break; } } System.out.println("์ข
๋ฃ"); } }
๊ฒฐ๊ณผ)
a ์
๋ ฅ๋ ๋ฌธ์์ด: "a" q ์
๋ ฅ๋ ๋ฌธ์์ด: "q" ์ข
๋ฃ
์๋ฐ๋ ๊ธฐ๋ณธ ํ์
(byte, short, int, long, float, double, boolean)์ ๊ฐ์ด ๋์ผํ์ง ๋น๊ตํ ๋์๋ ==๋ฅผ ์ฌ์ฉํ๊ณ ,
๋ฌธ์์ด(String)์ด ๋์ผํ์ง ๋น๊ตํ ๋์๋ equals() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ค. p. 97
boolean result = inputData. equals("๋น๊ต๋ฌธ์์ด");
inputData: ์ ์ฅ๋ ๋ฌธ์์ด
equals("๋น๊ต๋ฌธ์์ด"): ๋น๊ต
result: ๊ฐ์ผ๋ฉด true, ๋ค๋ฅด๋ฉด false
์์ ) p. 121
String strVar1 = "์ ์ฉ๊ถ"; String strVar2 = "์ ์ฉ๊ถ"; System.out.println(strVar1.equals(strVar2)); //true System.out.println(!strVar1.equals(strVar2)); //false
๋ง๋ฌด๋ฆฌ p. 98
๋ฐ์ดํฐ ์์ค ์ต์ํ
=== console์ ๊ฒฐ๊ณผ ์ถ๋ ฅ ===
1) System.out.println(): ๊ดํธ์ ์ฃผ์ด์ง ๋งค๊ฐ๊ฐ์ ๋ชจ๋ํฐ๋ก ์ถ๋ ฅํ๊ณ ๊ฐํ(๊ฐ์ ์ค ๋ฐ๊ฟ)์ ํ๋ค.
2) System.out.print(): ๊ดํธ์ ์ฃผ์ด์ง ๋งค๊ฐ๊ฐ์ ๋ชจ๋ํฐ๋ก ์ถ๋ ฅํ ํ๊ณ ๊ฐํ์ ํ์ง ์๋๋ค.
3) System.out.printf(): ๊ดํธ์ ์ฃผ์ด์ง ํ์๋๋ก ์ถ๋ ฅํ๋ค.
=== ํค๋ณด๋๋ก ๊ฐ์ ์ ๋ ฅ ===
4) Sytem.in.read(): ํค๋ณด๋์ ์ ๋ ฅ๋ ํค๋ณด๋๋ฅผ ์ฝ๋๋ค.
5) Scanner: System.in.read()๋ ํค๋ณด๋๋ฅผ ํ๋์ฉ ์ฝ๊ธฐ ๋๋ฌธ์ 2๊ฐ ์ด์์ ํค๊ฐ ์กฐํฉ๋ ํ๊ธ์ ์ฝ์ ์ ์๋ค. ํค๋ณด๋๋ก๋ถํฐ ์ ๋ ฅ๋ ๋ด์ฉ์ ํต ๋ฌธ์์ด๋ก ์ฝ๊ธฐ ์ํด์ Scanner๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
Q1)
public class P98Q1 { public static void main(String[] args) { String name = "๊น์๋ฐ"; int age = 25; String tel1 = "010"; String tel2 = "123"; String tel3 = "4567"; System.out.println("์ด๋ฆ: " + name); System.out.print("๋์ด: " + age+"\n"); //1$: ์ฒซ ๋ฒ์งธ ๊ฐ, 2$: ๋ ๋ฒ์งธ ๊ฐ, n$: n๋ฒ ์งธ ๊ฐ System.out.printf("์ ํ : %1s-%2s-%3s", tel1,tel2,tel3); } }
๊ฒฐ๊ณผ)
์ด๋ฆ: ๊น์๋ฐ ๋์ด: 25 ์ ํ : 010-123-4567
Q2)
public class P99Q2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("์ฒซ๋ฒ์งธ ์:"); //String ํ์
์ผ๋ก ์ ์ฅํ๋ค. String strNum1 = scanner.nextLine(); System.out.println("๋๋ฒ์งธ ์:"); String strNum2 = scanner.nextLine(); int num1 = Integer.parseInt(strNum1); int num2 = Integer.parseInt(strNum2); int result = num1 + num2; System.out.println("๋ง์
๊ฒฐ๊ณผ:"+result); } }
๊ฒฐ๊ณผ) ์
๋ ฅํ ์ซ์ 2๊ฐ์ ํฉ์ด ๋ฌ๋ค.
์ฒซ๋ฒ์งธ ์: 15 ๋๋ฒ์งธ ์: 20 ๋ง์
๊ฒฐ๊ณผ:35
Q3)
import java.util.Scanner; public class P99Q3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("[ํ์ ์ ๋ณด ์
๋ ฅ]"); System.out.println("1. ์ด๋ฆ: "); String name = scanner.nextLine(); System.out.println("2. ์ฃผ๋ฏผ๋ฒํธ ์ 6์๋ฆฌ: "); String ssn = scanner.nextLine(); System.out.println("3. ์ ํ๋ฒํธ: "); String tel = scanner.nextLine(); System.out.println(); System.out.println("[์
๋ ฅ๋ ๋ด์ฉ]"); System.out.println("1. ์ด๋ฆ: " + name); System.out.println("2. ์ฃผ๋ฏผ ๋ฒํธ ์ 6์๋ฆฌ: " + ssn); System.out.println("3. ์ ํ๋ฒํธ: " + tel); } }
๊ฒฐ๊ณผ) ์ ๋ ฅํ ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ค.
[ํ์ ์ ๋ณด ์
๋ ฅ] 1. ์ด๋ฆ: ์๋
ํ์ธ์ 2. ์ฃผ๋ฏผ๋ฒํธ ์ 6์๋ฆฌ: 912345 3. ์ ํ๋ฒํธ: 0101234567 [์
๋ ฅ๋ ๋ด์ฉ] 1. ์ด๋ฆ: ์๋
ํ์ธ์ 2. ์ฃผ๋ฏผ ๋ฒํธ ์ 6์๋ฆฌ: 912345 3. ์ ํ๋ฒํธ: 0101234567