Java 게시판 #1일차

김신하·2023년 2월 13일
post-thumbnail

article write 구현

package com.KoreaIT.java.BasicAM;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

	System.out.println("==프로그램 시작==");
    
	Scanner sc = new Scanner(System.in);
    

//Scanner를 사용해서 콘솔창에 명령어를 입력받는다.

	while (true) {
		System.out.printf("명령어 ) ");
		String command = sc.nextLine();

// 입력 받은 명령어를 String 타입 변수 command로 받아들인다.

		if (command.length() == 0) {
			System.out.println("명령어를 입력해주세요");
			continue;
		}

// 입력받은 명령어의 길이가 0이랑 같다면 즉, 아무것도 입력되지 않았다면 ~라는 조건문이다.

		if (command.equals("system exit")) {
			break;
		}

// 입력받은 명령어가 "system exit"과 같다면 조건문을 중지한다.

		if (command.equals("article list")) {
			System.out.println("게시글이 없습니다");
		} else if (command.equals("article write")) {
			System.out.println("제목 : ");
			System.out.println("내용 : ");
		}

// 입력받은 명령어가 "article list"와 같다면 ~
// "article write"와 같다면 ~

		else {
			System.out.println("존재하지 않는 명령어입니다");
		}

// 그렇지 않다면 ~

	}

	System.out.println("==프로그램 끝==");

// "system exit"와 같다면 break을 통해 조건문이 끝나게 되는데 그 때 이 문장을 수행한다.

	sc.close();
}

}

profile
개발자로 취직하고싶다!

0개의 댓글