\n (백슬래시 n 으로 줄바꿈 가능)
문자열 뒤 or 두번째 시작문자열 앞 모두 사용가능 (동일결과)
문자내 \"\" 사용시 큰따움표 적용가능
ex
public class Main {
public static void main(String[]args) {
System.out.println("자바는\n");
System.out.println("재미있는 \"프로그래밍\"언어");
System.out.println("\n입니다");
*출력결과*
자바는
재미있는 "프로그래밍" 언어
입니다.
\t = 탭만큼 띄우기.
System.out.println("번호\t이름\t직업")
*출력결과*
번호 이름 직업
System.out.println("봄\\여름\\가을\\겨울")
*출력결과*
봄\여름\가을\겨울
public class Main {
public static void main(String[] args) {
String str = "1" + (2 + 3);
System.out.println(str);
}
}
*결과값
15
1은 문자열 5는 (2+3) 합산한 숫자
ex
public class Main {
public static void main(String[] args) {
int value = 10 + 2 + 8;
String str1 = 10 + 2 +"8";
String str2 = 10 + "2" + 8;
String str3 = "10" + 2 + 8;
String str4 = "10" + (2+8);
System.out.println(value);
System.out.println("str1:" + str1);
System.out.println("str2:" + str2);
System.out.println("str3:" + str3);
System.out.println("str4:" + str4);
}
}
* 결과값*
20
128
1028
1028
1010
public class Main {
public static void main(String[] args) {
int x = 1;
int y = 2;
double result = (double) x / y;
System.out.println(result);
}
}
*결과값*
0.5
*참고*
방법 1. double result = (double) x / y;
방법 2. double result = x / (double) y;
방법 3. double result = (double) x / (double) y;