JAVA

[게시판 만들기] #2 게시판 작성하기

leesein 2020. 12. 28. 21:47

주요 키워드

(1) "write" 명령어로 시작

(2) int lastArticleId

(3) scanner로 제목, 내용 받기

package com.exam5;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println("====프로그램 시작====");
		Scanner sc = new Scanner(System.in);
		
		int lastArticleId = 0;
		
		while(true) {
			System.out.printf("명령어) ");
			String commend = sc.nextLine();
			
			if(commend.equals("exit")) {
				break;
			}
			
			
			else if(commend.equals("write")) {
				int id = lastArticleId + 1;
				lastArticleId = id;
				
				System.out.printf("제목 : ");
				String title = sc.nextLine();
				System.out.printf("내용 : ");
				String body = sc.nextLine();
				
				System.out.println(id + "번째 글이 생성되었습니다.");
			}
			
			
			else {
				System.out.println("잘못된 명령어 입니다.");
			}
		}
		
		sc.close();
		System.out.println("====프로그램 종료====");
	}
}

 

결과 :)