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 |
Tags
- 유효성
- it지원
- interface default
- MariaDB
- resultType="hashmap"
- REST
- git message
- $('input [name=
- 자바 로또
- bubblesort
- templet
- 자바 예상문제
- 전역객체
- 포워드 엔지니어링
- ${}
- 최대값 최소값
- $(document).on
- 알고리즘
- #{}
- nodejs http
- git
- a href="#" onclick="return false"
- BCrypt
- container-fluid
- SQL
- map형태 jsp와 mapper
- nodejs
- cmd mariaDB
- git 명령어
- gradle 설치
Archives
- Today
- Total
Rubberduck-Debugging
삼항연산자 본문
삼항연산자
(조건식) ? 값1 : 값2
- 조건식이 참(True)일경우 값1을 리턴한다.
- 조건식이 거짓(False)일경우값2를 리턴한다.
public class MinMax {
private int[] score;
private int max ;
private int min;
private void minMax() {
//1. 수학과 학생들의 기말고사 시험 점수
score = new int[]{79,88,97,54,56,95};
max = score[0]; //79
min = score[0]; //79
for(int i:score) {
max = (score[i] > max) ? score[i] : max;
min = (score[i] < min) ? score[i] : min;
}
System.out.println("max : " + max);
System.out.println("min : " + min);
}
}
수학과 학생들의 기말고사 시험 점수를, 삼항연산자를 사용해서 최소, 최대값을 구해보았다.
max = (score[i] > max) ? score[i] : max;
score[i]가 max 값보다 큰게 참일 경우,
score[i] > max ? score[i] 에서 ? 앞의 값이, max로 들어간다.
min = (score[i] < min) ? score[i] : min
score[i]가 max 값보다 큰게 참일 경우,
score[i] > max ? score[i] 에서 ? 앞의 값이, max로 들어간다.
'개발자 > 20181127 교육과정' 카테고리의 다른 글
oracle query 문제 모음 (0) | 2018.12.14 |
---|---|
배열 선언과 초기화 (0) | 2018.12.12 |
eXERD 포워드 엔지니어링 연결설정 (0) | 2018.12.11 |
자바 로또, bubbleSort, FileWriter, math.random (0) | 2018.12.10 |
git ignore 적용 (0) | 2018.12.10 |