JAVA 기본

JAVA 기본 3-1

민초닷컴 2022. 3. 15. 21:51

OR연산자

|| : 앞의 피연산자가 true면 뒤에 연산자를 검사하지 않는다(실용적)

| : 피연산자 2개를 모두 검사(비효율적)

 

XOR연산자

^(배타적논리합) : 피연산자 중 한개는 true, 한개는 false일때, true 값을 반환

 

!isOnNotebook -> isOnNotebook == false

isOnNotebook -> isOnNotebook == true

 

삼항다항식

조건식 ? 연산식1 : 연산식2

조건식이 true면 연산식1로 이동하고, 조건식이 false면 연산식2로 이동

 

If, else if, else 조건문

if -> {}를 꼭 쓰자.

else if

else

 

Switch 조건문

switch~case~break

default(=else)

 

반복문(for)

for (int i = 0; i < 11; i++)

0~10  

 

*double randNum = Math.random(); -> 무작위 함수 0.0 ~ 0.9999999

 int divediceNumber = (int) (randNum * 10 + 1); -> 1~10

 int divediceNumber = (int) (randNum * 6 + 1); -> 1~6(주사위)

 

오늘의 단축키

Ctrl + D : 라인 삭제