@634

コンソールからの入力

Advertisement

一文字入力

//インポート
import java.io.*;

class InputTest{
    public static void main(String[] args){
        try{
            InputStreamReader in = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(in);

            System.out.print("一文字入力してください > ");
            System.out.println("入力した文字は:" + (char)in.read());
        }catch(IOException e){
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
}
実行結果
一文字入力してください > A
入力した文字は:A

文字列入力

//インポート
import java.io.*;

class InputTest{
    public static void main(String[] args){
        try{
            InputStreamReader in = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(in);
            System.out.print("文字列を入力してください > ");
            System.out.println("入力した文字列は:" + reader.readLine());

        }catch(IOException e){
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
}
実行結果
文字列を入力してください > ABCDE
入力した文字列は:ABCDE

Advertisement

ショートカット

634
634ブログ
このカテゴリのトップページに戻る
Incubator(Pukiwiki)
634ラボ
   UIコレクションギャラリー
   ZO-3ジェネレーター

サイト検索


Y!ログール