Notice
Recent Posts
Recent Comments
관리 메뉴

Developer Gonie

[1주차] 15. 조건식(if, else if, else) 본문

K-DigitalTraining 강의/1. Java

[1주차] 15. 조건식(if, else if, else)

이대곤 2022. 5. 18. 12:15

* if문에서 실행문이 한 줄이라면 {}는 아래와 같이 생략 가능하다. 보통은 {}으로 실행문을 감싸줘야 함.

코드

import java.util.Scanner;

public class Ex03_01_ifelse {
	public static void main(String[] args) {
		int a,b;
		Scanner sc= new Scanner(System.in);
		
		System.out.print("숫자1 입력:");
		a = sc.nextInt();
		System.out.print("숫자2 입력:");
		b = sc.nextInt();
		
		if(a>b) 
			System.out.println("a가 b보다 크다.");
		else if(a==b) 
			System.out.println("a와 b가 같다.");
		else
			System.out.println("a가 b보다 작다.");
		
		
		if(1<=a && a<=10) 
			System.out.println("a는 1~10 사이의 숫자이다.");
	}
}

실행결과

숫자1 입력:10
숫자2 입력:20
a가 b보다 작다.
a는 1~10 사이의 숫자이다.
Comments