nme.kr

문서의 이전 판입니다!


Chator05

5.2 조건문

if문

package chapter05;

public class IfEx {

	public static void main(String[] args) {
		
		int score = 70;
		
		System.out.println("시험 시작");
		if (score >= 60) {
			System.out.println("합격입니다.");
		}
		System.out.println("시험 끝");

	}

}

if else문

package chapter05;

public class IfEx1 {

	public static void main(String[] args) {
		
		int score = 50;
		
		System.out.println("시험 시작");
		if (score >= 60) {
			System.out.println("합격입니다.");
		} else {
			System.out.println("불합격입니다.");
		}
		System.out.println("시험 끝");

	}

}

if ~else if

package chapter05;

public class IfEx2 {

public static void main(String[] args) {
	
	int score = 80;
	String grade = "";
	
	System.out.println("학점부여 시작");
	if (score >= 95) {
		grade = "A+";
	} else if (score >= 90){
		grade = "A";
	} else if (score >= 85) {
		grade = "B+";
	} else if (score >= 80) {
		grade = "B";
	} else if (score >= 70) {
		grade = "C";
	} else if (score >= 60) {
		grade = "D";
	} else {
		grade = "F";
	}
	System.out.println("당신의 학점은 "+grade+"입니다.");
	System.out.println("학점부여 끝");
}

} </code>