Contents

1 レ 螻給葦 蠍
2 LinkedList 蠍


1 レ 螻給葦 蠍 #

import java.util.*;

public class ConsoleEx2 {

	static String[] argArr;
	
	public static void main(String[] args){
		while(true){
			String prompt = ">> ";
			System.out.print(prompt);
			
			Scanner lineStr = new Scanner(System.in);
			String lineInput = lineStr.nextLine();
			lineInput = lineInput.trim().replaceAll("\\s+", " ");

			argArr = lineInput.split(" ");		
			if(lineInput.equalsIgnoreCase("quit")){
				System.exit(0);
			} else {
				for(int i=0;i<argArr.length;i++){
					System.out.println(argArr[i]);
				}
			}
		} //while
	} //main
} //class


//intput : java ConsoleEx2.java aaa        bbb           ccc     

2 LinkedList 蠍 #

import java.util.*;

public class ConsoleEx2 {

	static String[] argArr;
	static LinkedList q = new LinkedList();
	static final int MAX_SIZE = 5;
	
	public static void main(String[] args){
		while(true){
			String prompt = ">> ";
			System.out.print(prompt);
			
			Scanner lineStr = new Scanner(System.in);
			String lineInput = lineStr.nextLine();
			save(lineInput);
			lineInput = lineInput.trim().replaceAll("\\s+", " "); //argArr = lineInput.split(" +"); 螻 螳 企 .  

			argArr = lineInput.split(" ");		
			if(lineInput.equalsIgnoreCase("quit")){
				System.exit(0);
			}
			else if (lineInput.equalsIgnoreCase("history")){
				history();
			} else {
				for(int i=0;i<argArr.length;i++){
					System.out.println(argArr[i]);
				}
			}
		} //while
	} //main
	
	public static void save(String input){
		if(input==null || "".equals(input)) return;
		q.add(input);
		if(q.size() > MAX_SIZE) q.remove();
	} //save
	
	public static void history(){
		int i=0;
		ListIterator it = q.listIterator();
		
		while(it.hasNext())
			System.out.println(++i + "." + it.next());
	}
} //class


//intput : java ConsoleEx2.java aaa        bbb           ccc