package characters;
public class Characters {
public static void main (String args[]) {
System.out.println("특수한 목적으로 사용되는 문자");
/*
* \t - 탭
* \n - 줄바꿈
* \' - 작은따옴표
* \" - 큰따옴표
* \\ - 역슬레쉬
*/
System.out.println("GoodMorning");
System.out.println("Good \t Morning");
System.out.println("Good \n Morning");
System.out.println("Good\'Morning~\'");
System.out.println("Good\"Morning~\"");
System.out.println("Good\\Morning~\\\n");
System.out.println("서식에 사용되는 문자");
/*
* %d - 10진수
* %o - 8진수
* %x - 16진수
* %c - 문자
* %s - 문자열
* %f - 실수
*/
System.out.println("println , printf 차이");
System.out.println("오늘의 기온은 10도 입니다.");
System.out.printf("오늘의 기온은 %d도 입니다.\n",11);
int nm = 21;
System.out.println("오늘의 온도는 "+nm+"도");
System.out.printf("오늘의 온도는 %d 도\n",nm);
System.out.printf("오늘의 온도는 %d도?%d도?%d도?\n",nm,nm+1,nm+2);
System.out.println("");
System.out.println("정수");
int num = 100;
System.out.printf("num(10진수) : %d\n", num);
System.out.printf("num(8진수) : %o\n", num);
System.out.printf("num(16진수) : %x\n", num);
System.out.println("\n문자");
System.out.printf("알파벳 문자 : %c, %c, %c, %c, %c, \n",'a','B','c','D','f');
System.out.println("\n문자열");
System.out.printf("알파벳 문자열: %s, %s\n","AbCdF","java");
System.out.println("\n실수");
float f = 1.122f;
System.out.printf("f= %f\n", f);
double d = 1.2332d;
System.out.printf("f= %f\n", d);
System.out.println("\n서식문자 정렬기능");
System.out.printf("%6d\n", 123);
System.out.printf("%6d\n", 12334);
System.out.printf("%6d\n", 123555);
System.out.println("\n서식문자 소수점 제한 기능");
System.out.printf("%f\n", 1.1234567);
System.out.printf("%.0f\n", 1.1234567);
System.out.printf("%.1f\n", 1.1234567);
System.out.printf("%.2f\n", 1.1234567);
System.out.printf("%.4f\n", 1.1234567);
System.out.printf("%.6f\n", 1.1234567);
}
}
결과 값
특수한 목적으로 사용되는 문자
GoodMorning
Good Morning
Good
Morning
Good'Morning~'
Good"Morning~"
Good\Morning~\
서식에 사용되는 문자
println , printf 차이
오늘의 기온은 10도 입니다.
오늘의 기온은 11도 입니다.
오늘의 온도는 21도
오늘의 온도는 21 도
오늘의 온도는 21도?22도?23도?
정수
num(10진수) : 100
num(8진수) : 144
num(16진수) : 64
문자
알파벳 문자 : a, B, c, D, f,
문자열
알파벳 문자열: AbCdF, java
실수
f= 1.122000
f= 1.233200
서식문자 정렬기능
123
12334
123555
서식문자 소수점 제한 기능
1.123457
1
1.1
1.12
1.1235
1.123457
'Develop > JAVA' 카테고리의 다른 글
JAVA 배열과 메모리 (0) | 2021.10.18 |
---|---|
JAVA 배열, Scanner (0) | 2021.10.14 |
JAVA 연산자 (0) | 2021.10.10 |
JAVA 변수 선언 및 자료형 (0) | 2021.09.26 |
JAVA 이클립스 설정 (0) | 2021.09.26 |