728x90
%(나머지)
//긁지않은 개발자
public class Ex01 {
public static void main(String[] args) {
String birth1 = "123456";
int birth2 = 123456;
System.out.println(birth2/10000);
System.out.println(birth2/100%100);
System.out.println(birth2%10000/100);
System.out.println(birth2%100);
System.out.println(birth1.substring(0,2));
System.out.println(birth1.substring(2,4));
System.out.println(birth1.substring(4));
}
}
실행 결과
12
34
34
56
12
34
56
//긁지않은 개발자
public class Ex02 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2/10000);
System.out.println(birth2/100%100);
System.out.println(birth2%10000/100);
System.out.println(birth2%100);
System.out.println(birth1.substring(0,2));
System.out.println(birth1.substring(2,4));
System.out.println(birth1.substring(4));
}
}
실행 결과
12
4
4
6
12
04
06
//긁지않은 개발자
public class Ex03 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2/10000 + "년");
System.out.println(birth2/100%100 + "월");
System.out.println(birth2%10000/100 + "일");
System.out.println(birth2%100 + "일");
System.out.println(birth1.substring(0,2) + "년");
System.out.println(birth1.substring(2,4) + "월");
System.out.println(birth1.substring(4) + "일");
}
}
실행 결과
12년
4월
4월
6일
12년
04월
06일
//긁지않은 개발자
public class Ex04 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2/10000 + "년");
System.out.println(birth2/100%100 + "월");
System.out.println(birth2%100 + "일");
}
}
실행 결과
12년
4월
6일
//긁지않은 개발자
public class Ex05 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2/10000 + "년");
}
}
실행 결과
12년
//긁지않은 개발자
public class Ex06 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2/100%100 + "월");
System.out.println(birth2%10000/100 + "월");
}
}
실행 결과
4월
4월
//긁지않은 개발자
public class Ex07 {
public static void main(String[] args) {
String birth1 = "120406";
int birth2 = 120406;
System.out.println(birth2%100 + "일");
}
}
실행 결과
6일
연산자와 연산식 관련 포스팅
https://h0-0cat.tistory.com/entry/%EC%97%B0%EC%82%B0%EC%9E%90%EC%99%80-%EC%97%B0%EC%82%B0%EC%8B%9D
[JAVA] 연산자와 연산식
연산이란 ? 프로그램에서 데이터를 처리하여 결과를 산출하는 것을 연산이라고 한다. < 연산자와 연산식 > 단항 연산자 : ++x; 이항 연산자 : x+ y; 삼항 연산자 : (sum>90) "A" : "B"; 연산식은 반드시 하
h0-0cat.tistory.com

728x90
'JAVA > JAVA 이용하기' 카테고리의 다른 글
[JAVA] JAVA Boolean타입 ( true/false) (0) | 2023.06.10 |
---|---|
[JAVA] JAVA 산술연산자 (0) | 2023.06.10 |
[JAVA] JAVA if조건문, scanner (0) | 2023.06.10 |
[JAVA] JAVA 현재 날짜 출력하기 (0) | 2023.06.09 |
[JAVA] JAVA print, println, printf 사용법과 실행 결과 (0) | 2023.06.09 |