Back - end/JAVA
23.03.20
낫쏘링
2023. 3. 20. 09:01
728x90
package ch04.sec05;
import java.util.Scanner;
public class KeyControlExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean run = true;
int speed = 0;
while(run) {
System.out.println("-----------------------------");
System.out.println("1. 증속 | 2. 감속 | 3. 중지");
System.out.println("-----------------------------");
System.out.print("선택: ");
String strNum = scanner.nextLine();
if(strNum.equals("1")) {
speed++;
System.out.println("현재 속도 = " + speed);
} else if(strNum.equals("2")) {
speed--;
System.out.println("현재 속도 = " + speed);
} else if(strNum.equals("3")) {
run = false;
}
}
System.out.println("프로그램 종료");
}
}
입력 받는 함수 scanner.nextLine();
객체 지향
클래스와 인스턴스
객체참조변수를 인스턴스 변수라고 할 수 있다.
728x90