5月 11th, 2008at 1:12
Tags: Java
J2SE1.5 Scanner
使用例
String input = "こんにちは! さようなら! また来週!";
Scanner sc = new Scanner(input);
// デフォルトでは区切り文字は空白文字System.out.println("空白文字区切りでスキャン***************");while(sc.hasNext()){ System.out.println(sc.next());}
// 区切り文字を指定することもできるsc = new Scanner(input);sc.useDelimiter("!");System.out.println("!区切りでスキャン***************");while(sc.hasNext()){ System.out.println(sc.next());}
// intでスキャンすることもできるinput = "1 2 3 4 5";sc = new Scanner(input);sc.useDelimiter(" ");System.out.println("intをスキャン***************");while(sc.hasNextInt()){ System.out.println(sc.nextInt());}
// コマンドプロンプトで入力した文字列を表示sc = new Scanner(System.in);String inputString = (String)sc.next();
System.out.println("input = " + inputString);
sc.close();
実行結果
空白文字区切りでスキャン***************:こんにちは!さようなら!また来週!!区切りでスキャン***************:こんにちは さようなら また来週intをスキャン***************:12345test string<Enter>input = test
I'm a software engineer who like travel to island in Japanese. Recently I am enjoying agile manager, coach, product owner for my work. The person grows like that.








