+ : 덧셈의 의미
+ : 연결의 의미
- println("문자" + 숫자); ==> 문자숫자
- println("문자" + 숫자); ==> 숫자문자
- println("문자" + "문자"); ==> 문자문자
- println("문자" + 숫자 + 숫자) ==>문자숫자숫자
+ : 연결 및 덧셈의 의미
- println("문자" + (숫자 + 숫자)) ==> 문자+(더한숫자)
문제를 풀어보자~
화면에 출력되는 값은?
System.out.println(10 + 23);
System.out.println("10" + 23);
System.out.println("10" + 4 + 7);
System.out.println("10" + (4 + 7));
System.out.println(10 + "23");
답 :
System.out.println(10 + 23); ==> 33
System.out.println("10" + 23); ==> 1023
System.out.println("10" + 4 + 7); ==> 1047
System.out.println("10" + (4 + 7)); ==> 1011
System.out.println(10 + "23"); ==> 1023
JAVA에서의 출력 양식
- system.out.println()
- system.out.print()
- system.out.printf()
: f는 format의 약자
- %d : 정수 출력 시
system.out.printf("%d + %d = %d", 10, 20, (10 + 20));
==> 30
system.out.printf("%d", 10000000);
==> 10000000
system.out.printf("%,d", 10000000);
==> 10,000,000
- %f : 실수 출력 시
system.out.printf("%f", 3.2582);
==> 3.258200
system.out.printf("%.2f", 3.2582)
==> 3.26
- %o : 8진수(: 0부터 7사이의 값) 출력 시
system.out.printf("8진수는 >>> %o", 10);
==> 8진수는 >>> 12
- %x : 16진수 출력 시
system.out.printf("16진수는 >>> %x", 15);
==> 16진수는 f
** 이미지 참고