본문 바로가기

개발자노트

Scanner 문자열 예제(신호등)

package parctice;

import java.util.Scanner;

public class Line {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		System.out.print("색 입력(빨강|노랑|초록): ");

		String color = sc.next();

		if (color.equals("빨강")) {

			System.out.println("정지");

		}

		else if (color.equals("노랑")) {

			System.out.println("주의");

		}

		else if (color.equals("초록")) {

			System.out.println("출발!");

		}

		else {

			System.out.println("?????");

		}

	}

}