_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › ConsoleEx2

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     
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

語 覦 覲伎 覓伎 蠍壱 一企.