JAVA/수업 복습

자바 공부기록 12 - QuestionMark

본이qq 2022. 4. 7. 17:55

●QuestionMark

 

-점수가 70점 이상이면 합격, 아니면 불합격을 출력하세요

 

1
2
3
4
5
6
7
8
9
10
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        System.out.printf("점수를 입력하세요 : ");
        int score = sc.nextInt();
        
        String prnText;
        //if( score >= 70) prnText = "합격";
        //else prnText = "불합격";
        prnText = (score >= 70)? "합격" : "불합격";
        System.out.println("입력한 점수는 " + prnText + " 입니다");
cs

 

-if, else문이 아니라 prnText = (score >= 70)? "합격" : "불합격";로 가능

 

 

 

 

 

 

-기본급 100만원 이상이면 50%, 100만원 미만이면 60% 가산하여 지급액을 출력

 

1
2
3
4
5
6
7
8
9
10
11
12
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);        
        System.out.printf("기본급을 입력하세요 : ");        
        int a = sc.nextInt();
 
        //코드#1
        double per = (a >= 1000000)? 0.5 : 0.6;
        System.out.println("총지급액" + (int)(a + a*per));
        
        //코드#2
        double b = (a>=1000000)? a + a*0.5 : a + a*0.6;
        System.out.println("총지급액" + (int)b);
cs