Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 의존성주입
- 이클립스
- 영속성 컨텍스트
- 깃허브
- springboot
- 어노테이션
- Spring legacy Project
- 상속
- 자동주입
- java
- 리액트
- 스프링 컨테이너
- pom.xml
- 트랜잭션
- DI
- 자바
- github
- @transactional
- merge
- spring
- 빈
- 스프링
- mysql
- 인터페이스
- @Bean
- Spring 개발환경 설정
- react
- list
- 객체
- JVM
Archives
- Today
- Total
DEVLOG
연산자 본문
1. 초 입력하여 '몇분 몇초' 형태 출력하기
public class Main {
final static int SECOND = 1000;
public static void main(String[] args) {
int minute = SECOND / 60; //'/' : 121s라면 몫 2m만 출력
int second = SECOND % 60; //'%' : 121s라면 나머지 1s만 출력
System.out.println(minute + "분 " + second + "초");
}
}
2. 증감연산자 : ++ --
public class Main {
public static void main(String[] args) {
int a = 10;
System.out.println("현재의 a는 " + a + "입니다."); //10
a++; // '++' : 증감 연산자
System.out.println("현재의 a는 " + a + "입니다."); //11
System.out.println("현재의 a는 " + ++a + "입니다."); //12
System.out.println("현재의 a는 " + a++ + "입니다."); //12
//a++ : 출력 후 +1 증가시킨다. 출력값은 12지만 출력 후 13으로 변환됨
System.out.println("현재의 a는 " + a + "입니다."); //13
}
}
3. 모듈러 연산
public class Main {
public static void main(String[] args) {
//모듈러 연산
System.out.println(1 % 3); //1
System.out.println(2 % 3); //2
System.out.println(3 % 3); //0
System.out.println(4 % 3); //1
System.out.println(5 % 3); //2
System.out.println(6 % 3); //0
}
}
4. 논리 연산자
public class Main {
public static void main(String[] args) {
//논리 연산자
int a = 50;
int b = 50;
System.out.println("a와 b가 같은가요? " + (a==b));
System.out.println("a가 b보다 큰가요? " + (a>b));
System.out.println("a가 b보다 작은가요? " + (a<b));
//And 연산자
System.out.println("a가 b보다 같으면서 a가 30보다 큰가요? " + ((a==b) && (a>30)));
//Not 연산자
System.out.println("a가 50이 아닌가요? " + !(a==50));
}
}
5. 삼항 연산자
public class Main {
//static 클래스 전반적으로 사용되는 함수
public static void main(String[] args) {
int x = 50;
int y = 60;
System.out.println("최댓값은 " + max(x,y) + "입니다.");
}
//삼항 연산자 : 반환형, 함수이름, 매개변수
//함수 앞 static : 정적
static int max(int a, int b) {
int result = (a > b) ?a :b;
return result;
}
}
** Static : 인스턴스를 생성하지 않아도 호출이 가능
6. pow : 거듭제곱
public class Main {
public static void main(String[] args) {
//내장된 라이브러리 Math 활용하여 거듭제곱 구현
double a = Math.pow(3.0, 20.0);
System.out.println("3의 20제곱은 " + (int) a + "입니다.");
}
}
7. Or 연산자
public class Main {
public static void main(String[] args) {
int a = 10;
// a에 a+1을 넣어라.
// a = a+1;
// 간략하게
a += 1; //11
//'||' : Or 연산자
System.out.println((100 < a) || (a <200)); //true
}
}
Comments