본문 > https://velog.io/@si9138/vipb8bep
public class Exam08 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int kor = 0;
int eng = 0;
int math = 0;
int avg= 0;
//------여기까진 계획
System.out.println("국어 점수 :");
kor = sc.nextInt();
System.out.println("영어 점수 :");
eng = sc.nextInt();
System.out.printf("수학 점수 :");
math = sc.nextInt();
//-----여기까지 정보
avg = (kor+eng+math)/3; //연산과 출력
if(avg >= 60 && kor>40 && eng>40 && math>40) {
System.out.println("합격");
}else {
System.out.println("불합격");}
}
}
public class Exam09 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int kor;
int eng;
int a;
double b;
char c;
//------여기까진 계획
System.out.println("국어점수 입력: ");
kor = sc.nextInt();
System.out.println("영어점수 입력: ");
eng = sc.nextInt();
a = kor + eng;
b = a/2;
//switch((int)b/10에서 /10으로 나눈 이유는 정수로 바꾸면서
//소수점 자리를 없얘고 일의 자리수를 없얘기 위해 10으로 나누고 정수로 바꿨다.
switch((int)b/10) {
//switch byte, short, int, char만 가능
//b는 double 이므로 강제로 바꿈 float는 f붙여야해서 x
case 10:
case 9: c = 'A'; break; //원래 스위치는 순서대로 디폴트까지 진행이 되는데
case 8: c = 'B'; break; //해당되는것만 하고 빠지려고 break를 쓴다
case 7: c = 'C'; break;
case 6: c = 'D'; break;
default : c = 'f';} //위에 있는 케이스가 해당되지 않을 때 디폴트로 넘어가게하는것
//-----여기까지 정보
System.out.println("총점 = " +a);
System.out.println("평균 = " +b);
System.out.println("학점 = " +c);
3.
}
}
1번: 조건문 if(if,if-else,if-esle if-else),swich,3항 연산자: (조건식)?참일때 실행될 구문 : 거짓일 때 실행될 구문
2번: o, o, o, x(byte, short, int, char, string)
3번:
등급은
B
입니다.
4번: 어떤 혜택을 원하세요?
혜택이 없습니다.
감사합니다
첫번째 swich문으로 계산방법
public class Exam10_my2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//선언
double num1 = 0, num2 = 0;
double result = 0;
char operator = 0;
//------여기까진 계획
System.out.println("첫 번째 수 입력 : ");
num1 = sc.nextDouble();
System.out.println("두 번째 수 입력 : ");
num2 = sc.nextDouble();
System.out.println("연산자 : ");
operator = sc.next().charAt(0);
//-----여기까지 정보
//연산
switch(operator) {
case '+': result = num1+num2; break;
case '-': result = num1-num2; break;
case '*': result = num1*num2; break;
case '/': result = num1/num2; break;
case '%': result = num1%num2; break;
default:System.out.println("연산자를 정확히 입력해주세요");
}
//출력
System.out.println(num1+" "+operator+ " "+ num2+" = "+result);
}
}