Java

[Keyword] Java - else 키워드 - if 조건문에서 if 조건이 거짓일 때 실행할 내용.

1,436
목차
  1. else 예제 - if ... else ... 구문
  2. else 정의
  3. else 예제 - if ... else if ... else ... 구문

 

else 예제 - if ... else ... 구문

 

public class Hz {

  public static void main(String[] args) {

    int time = 15;

    if (time < 12) {

      System.out.println("오전");

    } else {

      System.out.println("오후");

    }  

  }

}

 

 

else 정의

 

if 조건문에서 if 조건이 거짓일 때 실행할 내용 지정.

 


PS.

 

if... : if 조건이 참이면 실행.

...else if ... : if 조건이 거짓이면 실행.  (※ 0개 이상 가능.)

...else ... : if 및 else if 조건이 거짓이면 실행.

switch : 경우 선택 조건문.

 

 

else 예제 - if ... else if ... else ... 구문

Hz.java

 

public class Hz {

  public static void main(String[] args) {

    int time = 20;

    if (time < 12) {

      System.out.println("오전");

    } else if (time < 18) {

        System.out.println("오후");   

    } else {

      System.out.println("저녁");

    }  

  }

}

 



분류 제목
class Java - Exceptions (= Try...Catch..) - 에러 제어 (= 익셉션 = 트라이...캐…
class Java - RegEx (정규식) - 정규표현식
class Java - Threads (쓰레드)
class Java - Lambda (람다 표현식)
file Java - File 클래스 + 메서드
file Java - Create/Write Files (파일 생성/쓰기)
file Java - Read Files (파일 읽기) - 파일 정보 얻기
file Java - Delete Files (파일 삭제)
Keyword Java - Keywords (키워드) 종류
Keyword Java - abstract 키워드 - 추상 (클래스/메서드) 선언.
Keyword Java - assert 키워드 △ - 디버깅 할 때 사용.
Keyword Java - boolean 키워드 - 참거짓 자료형 지정.
Keyword Java - break 키워드 - (반복문・switch 조건문) 탈출. (= 브레이크)
Keyword Java - byte 키워드 - 1byte 크기의 '정수형' 자료형 지정. (= 바이트)
Keyword Java - case 키워드 - switch 조건문의 각 조건 지정.
4/13
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인