조건문
2023. 8. 28. 16:15ㆍjava
if > 만약에
else if > 그렇지 않고 만약에
else > 그것도 아니라면

만족 한다면 -> 지정된 명령
만족 하지 않다면 --> 다음 명령

import java.util.Scanner;
public class 조건문 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("몇살입니까? : ");
int a = sc.nextInt();
if(a>=20) {
System.out.println("성인입니다.");
}
}
}
.next -> 문자열을 입력할때
.nextInt -> 숫자를 입력할때

import java.util.Scanner;
public class 조건문5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//각 과목별 개수
System.out.print("DB : ");
int a = sc.nextInt();
System.out.print("전자계산기 구조 : ");
int b = sc.nextInt();
System.out.print("OS : ");
int c = sc.nextInt();
System.out.print("데이터통신 : ");
int d = sc.nextInt();
System.out.print("소프트웨어공학 : ");
int e = sc.nextInt();
// 총 개수가 60개 미만이지 확인
int f =a+b+c+d+e;
// 어떤 조건이라도 하나만 만족하면 불합격
if(f<60 || a<8 || b<8 || c<8 || d<8 || e<8) {
System.out.println("불합격입니다.");
}else {
System.out.println("합격입니다.");
}
}
}'java' 카테고리의 다른 글
| 반복문 <-- while문 (0) | 2023.08.29 |
|---|---|
| TestEquals (0) | 2023.08.29 |
| 연산자 (0) | 2023.08.28 |
| 진수 (0) | 2023.08.28 |
| 논리형 (0) | 2023.08.28 |