왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • unsupervised
  • UnboundLocalError
  • TensorFlow
  • numpy
  • PIL
  • OpenCV
  • encoding='utf-8'
  • imageprocessing
  • pip install labelme
  • ckpt_file
  • 기상탐사
  • alibi-detection
  • tune()
  • labelme UnocodeDecodeError
  • labelme
  • PYTHON
  • get_long_description
  • maskimage
  • 컴퓨터비전
  • matplotlib
  • alibidetect
  • 영상처리역사
  • 의료이미징
  • 영상처리
  • 비지도학습
  • yolov8
  • ComputerVision
  • pytorch
  • 딥러닝
  • 영상기술

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

Java

Java - 조건문 사용 방법 (if/switch)

2023. 1. 18. 11:30
728x90

1. if

1.1. 구문

  • if - else if - else 로 구성
    • if - else로도 구성 가능
  • if 단독 사용 가능
  • else if, else는 단독 사용 불가
  • 조건에 만족할 시, 이후 조건은 검색하지 않음
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int a = 10;
		int b = 20;
		System.out.println( a == b );
		System.out.println( a != b );
		System.out.println( a > b );
		System.out.println( a < b );
		System.out.println( a >= b );
		System.out.println( a <= b );
		
		int c = 30;
		int d = 25;
		System.out.println( a == 10 && c == d );
		
		System.out.println( a == 10 && c != d );
		
		System.out.println( a == 10 || c == d );
		
		System.out.println( a != 10 || c <= d );
		
		// 코멘트를 달 때는 이렇게 하거나
		
		/* 여러줄을 걸쳐서 하고싶을
		 * 때에는 이거 사용해도
		 * 된다.
		 */
		
		if (a > 10) {
			System.out.println("hello");
		} else {
			System.out.println("Bye~");
		}
		
		int score = 60;
		// 스코어가 90점 이상이면 A
		// 70이상 90미만이면 B
		// 60~70 C
		// 나머지는 F
		if (score>=90) {
			System.out.println("A");
		} else if (score>=70 && score<90) {
			System.out.println("B");
		} else if (score>=60 && score<70) {
			System.out.println("C");
		} else {
			System.out.println("F");
		}
		

	}

}

2. switch

2.1. 구문

  • 수식에 맞는 값을 분류하여 코드를 실행
public class Switch {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int a = 10;
		
		switch(a) {
		case 1:
			System.out.println("hello");
			break;
		case 2:
			System.out.println("Bye");
			break;
		case 3:
			System.out.println("Good~");
			break;
		case 4:
			System.out.println("Nice");
			break;
		default :
			System.out.println("the end");
			break;
		}
		
		String month = "4월";
		
		switch(month) {
		case "1월":
		case "2월":
		case "12월":
			System.out.println("겨울");
			break;
		case "3월": case"4월": case"5월":
			System.out.println("봄");
			break;
			
		}

	}

}

'Java' 카테고리의 다른 글

Java - 클래스 (객체, 인스턴스 변수(=멤버 변수), 메소드)  (0) 2023.01.18
Java - 함수의 정의 ( 데이터타입, 함수명, 파라미터 )  (0) 2023.01.18
Java - 배열 (선언과 생성, 사용 방법,데이터 억세스,배열의 길이 구하는 방법 length)  (0) 2023.01.18
Java - 반복문 사용 방법 (for/while)  (0) 2023.01.18
Java,eclipse - 설치하기, 환경 변수 설정하기  (0) 2023.01.17
    'Java' 카테고리의 다른 글
    • Java - 함수의 정의 ( 데이터타입, 함수명, 파라미터 )
    • Java - 배열 (선언과 생성, 사용 방법,데이터 억세스,배열의 길이 구하는 방법 length)
    • Java - 반복문 사용 방법 (for/while)
    • Java,eclipse - 설치하기, 환경 변수 설정하기
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바