-2

ユーザーは文字列変数の値を入力できません。

これはプログラムです:

import java.io.*;
public class testing
{
  char a;
  int b;
  double c;
  String d;
  public void method() throws IOException
  {
     BufferedReader p=new BufferedReader(new InputStreamReader(System.in));
     System.out.println("Enter a variable of type 'char'");
     a = (char)p.read();
     System.out.println("Enter a variable of type 'string'");
     d = p.readLine();
     System.out.println("Enter a variable of type 'integer'");
     b = Integer.parseInt(p.readLine());
     System.out.println("Enter a variable of type 'double'");
     c = Double.parseDouble(p.readLine());
     System.out.println("Your values are: string-" +d +", integer-" +b +", double-" +c);
  }
}

誰かが問題を見ることができますか?

4

1 に答える 1

5

私はそれをテストしました、あなたのプログラムは期待通りに動作します。唯一の問題はread、charの読み取りに使用することですが、ユーザーがEnterキーを押すまで、Javaはユーザー入力を表示しません。私のテスト実行を参照してください:

Enter a variable of type 'char'
cchar
Enter a variable of type 'string'
Enter a variable of type 'integer'
12
Enter a variable of type 'double'
12
Your values are: string-char, integer-12, double-12.0
于 2013-02-19T12:21:17.977 に答える