:문자형(char)/탈출문자/택스트 블록
package chapter02.data;
public class CharType {
public static void main(String[] args) {
// 문자형(char)
char ch = '한';
char ch2 = '\uD55C';
System.out.println(ch);
System.out.println(ch2);
int i = ch;
System.out.println(i);
//탈출문자(escape sequence)
System.out.println(" 안 녕 하 \n 세 요 ");
System.out.println(" 안 녕 하 \t 세 요 ");
System.out.println(" 안 녕 하 \' 세 요 ");
System.out.println(" 안 녕 하 \" 세 요 "); //"를 문자로서 쓰고 싶을때
System.out.println(" 안 녕 하 \\ 세 요 ");
//텍스트 블록(text block)
//java15 도입
String str = """
아름다운 이땅에 금수강산에
단군 할아버지가 "터" 잡으시고
'홍익인간' 뜻으로 나라세우니
대대손손 훌륭한 인물도 많아
""";
System.out.println(str);
}
}
:데이터 타입/자동형변환, 강제형변환
package chapter02.data;
public class DataType {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
[데이터 타입]
1.기본형 테이터 타입
-정수형
byte(1),short(2),int(4),long(8)
char(2) //정수형 & 문자형
-실수형
float(4),double(8)
-논리형
boolean(1)
2.참조형 데이터 타입
-기본형 데이터타입이 아닌 모든 "객체"
class,enum,array,interface
*/
//기본형 데이터 타입
byte a = 127; //128 err
short b = 12345;
int c = 1234567890;
long d = 12345678900L; //L,l
//eclipse에서는 int를 기본 숫자 타입으로 지정하고 있기 때문에,
//long 타입은 소문자 l 혹은 대문자 L 을 붙여 명시해야 한다.
char e = 'A';
float f = 3.14f; //f F
double g =3.14;
boolean h = true; //true or false
//java 11 var 타입명확x
var v1 = 'B';
var v2 = 123;
System.out.println(v1);
System.out.println(v2);
System.out.println("byte : " + a);
System.out.println("short : " + b);
System.out.println("int : " + c);
System.out.println("long : " + d);
System.out.println("char : " + e);
System.out.println("float : " + f);
System.out.println("double : " + g);
System.out.println("boolean: " + h);
//문자형 타입의 정수화
char alpha = 'A';
System.out.println(alpha);
System.out.println((int) alpha);
//정수형 타입의 문자화
char ch1 = 66;
System.out.println(ch1);
int ch2 =67;
System.out.println((char) ch2);
//상수 final
final double PI =3.14;
//자동 형변환
int aaa = 3;
double bbb =aaa;
System.out.println(bbb); //double 으로 표시 그래서.0붙음
//강제 형변환
double ccc = 3.14;
int ddd = (int) ccc;
System.out.println(ddd);
}
}
:가수,진수
package chapter02.data;
public class Radix {
public static void main(String[] args) {
// radix(가수, 진수) p.74
int a = 10;
int b = 015; //0으로 시작하면 8진수
int c = 0x10; // 0x, 0X로 시작하면 16진수
int d = 0b1001; //0b, 0B로 시작하면 2진수
System.out.println();
}
}