Sponsored By
















 

 

IF문 사용방법.

 

ㅁ. 조건문 IF문 방법3가지.

 

1. if() 단독사용하는 경우

; if뒤 ()안에 내용을 만족시키면 뒤에 중괄호({}) 안의 기능을 수행. 

                    만족시키지못하면 if문 밖으로 빠져나옴.

2. if() ~ else 인 경우

; if뒤 ()안을 만족시키면 뒤에 중괄호({}) 안의 기능을 수행.

            만족시키지 못하면 else뒤에 중괄호({}) 안의 기능을 수행.

3. if() ~ else if() ~ else if() ~ (else) 인 경우

; if ()안을 만족시키면 뒤에 중괄호({}) 안의 기능을  수행.

          만족시키지 못하면 다음 else if 뒤의 중괄호({}) 안의 기능을 수행.

 

 

 

 

※ IF문을 이용하여 미니 성적 테스터기를 만들어보자.

 

00_1. 아래와 같이 90점 이상은 A 80점 이상은 B 나머지는 C 로 출력되게 코딩후 실행해보자.

      실행후 콘솔창에 점수를 입력해보자.








00_2. 맞게 나오는 것을 확인 할 수 있다.

 

 

 

 

 

 

 ※. 코드

 

 

import java.util.Scanner;

 

public class Test 

{

 

public static void main(String[] args) 

{

 

/* 미니 성적판단기 */

int input;

Scanner scan = new Scanner(System.in);

System.out.println("점수를 입력하세요");

 

input = scan.nextInt();

 

if(input >=90)

{

System.out.println("A");

}else if(input>=80)

{

System.out.println("B");

}else

{

System.out.println("C");

}

 

 

}  // main

 

 

}  // Class

 

 

 

 



Sponsored By















+ Recent posts