if문 문법
package control;
public class IfEx {
public static void main(String[] args) {
int age = 25;
if (age >= 20) {
System.out.println("Adult");
} else if (age >= 8){
System.out.println("Student");
} else {
System.out.println("Kid");
}
if (age >= 20) System.out.println("Adult");
}
}
if문을 활용해 Id, Pw 확인
package control;
import java.util.Scanner;
public class IfEx2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String id = sc.next();
int pw = sc.nextInt();
if (id.equals("kalzordy")) {
if (pw == 1234) {
System.out.println("Login is Success");
} else {
System.out.println("Wrong Pw");
}
} else {
System.out.println("Wrong Id");
}
sc.close();
}
}
Scanner 객체를 만들어 Enter를 기준으로 사용자 입력을 받아 진행
- 추후 java.util.Scanner를 공부하고 관련내용 게재
- 반드시 객체 생성 후 "sc.close();"로 닫아주자!