【初心者・ネタ】Java質問・相談スレ【大歓迎】
■ このスレッドは過去ログ倉庫に格納されています
0642デフォルトの名無しさん
NGNGimport java.util.NoSuchElementException;
import java.util.StringTokenizer;
public class StringTokenizerSample {
public static void main( String[] args ) {
String message = new String( "おはよう/こんにちは/こんばんわ" );
byte[] inputBytes = new byte[1];
StringTokenizer tokenizer = new StringTokenizer( message , "/" );
System.out.println( message );
System.out.println( "どの部分を表示するか選んでください(1-3)" );
try {
System.in.read( inputBytes );
}
catch( IOException e ) {
System.out.println( e.getMessage() );
System.exit( 1 );
}
String inputString = new String( inputBytes );
int inputValue = 0;
try {
inputValue = Integer.decode( inputString ).intValue();
}
catch( NumberFormatException e ) {
System.out.println( e.getMessage() );
System.exit( 1 );
}
String outputValue;
try {
for( int i = 1; true; i++ ) {
outputValue = tokenizer.nextToken();
if( i == inputValue ) {
System.out.println( outputValue );
}
}
}
catch( NoSuchElementException e ) {
}
System.exit( 0 );
}
}
■ このスレッドは過去ログ倉庫に格納されています