Search

if ~ else if ~ else

import java.util.Scanner; public class Ex03_ElseIf { public static void main(String[] args) { // ์„ฑ์ ์„ ์ž…๋ ฅ๋ฐ›์•„์„œ, ์„ฑ์ ์— ๋”ฐ๋ฅธ ํ•™์  A~F ๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค. Scanner sc = new Scanner(System.in); System.out.print("์„ฑ์  : "); int score = sc.nextInt(); char grade = 'F'; // if // 90 ์  ์ด์ƒ, A // 80 ์  ์ด์ƒ, B // 70 ์  ์ด์ƒ, C // 60 ์  ์ด์ƒ, D // 60 ์  ๋ฏธ๋งŒ, F if( score >= 90 && score <= 100 ) grade = 'A'; if( score >= 80 && score < 90 ) grade = 'B'; if( score >= 70 && score < 80 ) grade = 'C'; if( score >= 60 && score < 70 ) grade = 'D'; if( score < 60 && score >= 0 ) grade = 'E'; System.out.println("ํ•™์  : " + grade); // if ~ else if~else if( score >= 90 && score <= 100 ) grade = 'A'; else if( score >= 80 ) grade = 'B'; else if( score >= 70 ) grade = 'C'; else if( score >= 60 ) grade = 'D'; else grade = 'E'; System.out.println("ํ•™์  : " + grade); sc.close(); } }
Java
๋ณต์‚ฌ