Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Java
- JSP
- 생성자
- AWT
- Android
- paint
- 메소드
- struts2
- 메서드
- layout
- 예외처리
- 전화걸기
- mybatis
- Eclips
- 배열
- HTML
- oracle
- 안드로이드
- JavaScript
- 이클립스
- 클래스
- 에러페이지
- OGNL
- Graphic
- 기본
- 어노테이션
- 국제화
- Menu
- 오버로딩
- Spring
Archives
- Today
- Total
note
if문 본문
public class If01 {//if 문
public static void main(String[] args){
int num; //변수의 선언
num = -5; //변수 초기화
if(num < 0)//{} 괄호 한줄일경우 생략가능
num = -num;
System.out.println(" absolute num = " + num);
num = 5;
if(num <0)//false 이기에 실행하지 않음
num = -num;
System.out.println(" absolute num = " + num);
}
}
absolute num = 5
absolute num = 5
public class Exam02 {//if else
public static void main(String[] args){
//입력값 받아오는
java.util.Scanner input=
new java.util.Scanner(System.in);
int a;
System.out.print(" 정수형 데이터 한 개를 입력하세요. >>");
a = input.nextInt(); //함수
if(a%2==1)
System.out.println(" 홀수이다.");
else
System.out.println(" 짝수이다.");
}
}
정수형 데이터 한 개를 입력하세요. >>0
짝수이다.
public class If05 {//if else if
public static void main(String[] args){
java.util.Scanner input=
new java.util.Scanner(System.in);
System.out.print ("점수 : ");
int score = input.nextInt();
if(score >= 90 && score <= 100)
System.out.println("A학점");
else if(score >= 80 && score <= 89)
System.out.println("B학점");
else if(score >= 70 && score <= 79)
System.out.println("C학점");
else if(score >= 60 && score <= 69)
System.out.println("D학점");
else
System.out.println("F학점");
}
}
점수 : 24
F학점