ex )
class Example1{
//메인메소드 정의
//int형 변수 num1, num2를 정의하세요
//num1을 10으로 num2를 20으로 초기화 하세요
//num1과 num2를 더한 값을 출력하세요
class Example1{
public static void main(String[] args){
int num1=10;
int num2=20;
System.out.println(num1+num2);
}
}
if else 예제)
class Example1If1{
public static void main(String[] args){
int n1 = 5;
int n2 = 7;
if(n1 < n2){
System.out.println("n1 < n2 is true");
} else if (n1 > n2) {
System.out.println("n1 > n2 if true");
} else {
System.out.println("thats false");
}
}
}
if else 예제_1)
class AgeTest{
//int형 변수 age를 정의하세요
//age를 19로 초기화 하세요
//만약 age가 12이하 이면 어린이
//만약 age가 12초과 19이하면 청소년
//무엇도 아니라면 성인을 출력하세요
class AgeTest{
public static void main(String[] args){
int age = 19;
if(age<=12){
System.out.println("어린이");
} else if(age<=19){
System.out.println("청소년")
} else {
System.out.println("성인")
}
}
}
if else 예제 2)
class ScoreExample{
public static void main(String[] args)}
int score = 88;
// 90점 이상 : A
// 80점이상: B
// 70점 이상:C
// 60점 이상:D
//그외 : F
class ScoreExample{
public static void main(String[] args)}
int score = 88;
if(score>=90){
System.out.println ("A") ;
}else if(score>=80){
System.out.println ("B") ;
}else if(score>=70){
System.out.println ("C");
}else if(score>=60){
System.out.println ("D");
}else ( ){
System.out.println ("F");
}
}
}
if else 예제 3)
class SearchMax{
public static void man(String[] args){
//int 형 변수 a, b, c를 정의하세요
//a, b, c를 각각 9, 12, 84초로 초기화 하세요
//if(else if)문을 사용해서
//세 수 중 가장 큰 값을 출력하세요
if(a>= b && .....){
class SearchMax{
public static void main(String[] args){
int a = 9;
int b = 12;
int c = 1;
if(a>b && a>c){
System.out.println("a");
}else if(b>a && b>c){
System.out.println("b");
}else{
System.out.println("c");
}
}
}
'JAVA' 카테고리의 다른 글
[Java] 수업 정리 _ 13 (24.11.12) (0) | 2024.11.14 |
---|---|
[Java] 수업 정리 _ 12 (24.11.12) (0) | 2024.11.14 |
[Java] 수업 정리 10 break, continue, return문 (24.11.12) (0) | 2024.11.14 |
[Java] 수업 정리 9 while, do-while, for문 (24.11.12) (0) | 2024.11.14 |
[Java] 수업 정리 8 if, if-else,switch문 (24.11.12) (1) | 2024.11.12 |