๋ณ์
๊ฐ์ 1
public class Variable {
public static void main(String[] args) {
int a = 1; //Number -> integer
System.out.println(a);
//int b = 1.1; ์ ์๊ฐ ์๋๋ผ์ ๋ถ๊ฐ! 1.1์ real number ->double
double b = 1.1;
System.out.println(b);
//int c = "Hello World"; ๋ถ๊ฐ!
String c = "Hello World"; // string
System.out.println(c);
}
}
๊ฐ์2
public class Letter {
public static void main(String[] args) {
String name = "Iseo";
System.out.println("Hello, "+name+" ... "+name+" ... Iseo ... bye");
double VAT = 10.0;
System.out.println(VAT); //double ์ค์
}
}

๊ฐ์3 - CASTING

public class Casting {
public static void main(String[] args) {
double a = 1.1;
double b = 1;
double b2 = (double) 1;
System.out.println(b); //1์ด ์๋ 1.0์ผ๋ก converting
//int c = 1.1; //์คํ ์๋จ! ์ค๋ฅ๋จ
double d = 1.1;
int e = (int) 1.1; //๊ฐ์ ๋ก int๋ก ๋ณํ
System.out.println(e);
//1 to String
String f = Integer.toString(1);
System.out.println(f.getClass()); // f์ classํ์ธํ๊ธฐ
}
}

'Language > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ํ์ฝ๋ฉ] Java - ์ ์ด๋ฌธ (๋น๊ต์ฐ์ฐ์) (0) | 2022.04.25 |
---|---|
[์ํ์ฝ๋ฉ] Java - ์ ์ด๋ฌธ (boolean) (0) | 2022.04.25 |
[์ํ์ฝ๋ฉ] Java - ๋ฌธ์์ด (0) | 2022.04.14 |
[์ํ์ฝ๋ฉ] Java-์ซ์์ ์ฐ์ฐ (0) | 2022.04.14 |
[์ํ์ฝ๋ฉ] Java - ๋ฐ์ดํฐ์ ์ฐ์ฐ, ๋ฐ์ดํฐ ํ์ (0) | 2022.04.13 |
๋๊ธ