2016-04-03 25 views
-4

このコードの問題点は何ですか?私がそれを実行すると、コントロールは読み込みを待っています。 T実行回数と、それを表示するためのforループの中へconfiguration1を取るために -文字列オブジェクトの読み込みが制御されない

public static void main(String[] args) { 
    int T,N; 
    String configurationl; 
    System.out.println("Enter the number of test cases."); 
    java.util.Scanner sc=new java.util.Scanner(System.in); 
    T=sc.nextInt(); 
    System.out.println("Enter the configuration"); 
    configurationl=sc.nextLine(); 
    System.out.println("The configuration is: "+ configurationl); 
} 
+0

であろう? –

+0

コードへのリンクを投稿しないでください。 StackOverflowは、読者だけでなくOPも援助することを目的としており、リンクが悪くなるとリンクが役に立たなくなります。さらに悪いのは、IDEにコピー/ペーストできないコードの_images_へのリンクです。 –

+0

以下の回答は、昨年のBiswaranjanに役立ったのですか?ここで助けようとしている人に返信するのはやや習慣的です。 – halfer

答えて

1

あなたは、第2の入力ラインを入れたいです。コードがどこにある

public static void main(String[] args) { 
    int T, N; 
    System.out.println("Enter number of test cases: "); 
    Scanner in = new Scanner(System.in); 
    T = in.nextInt(); 

    String configuration1; 

    for (int i = 0; i < T; i++) { 
     System.out.println("Enter the configuration: "); 
     configuration1 = in.next(); 
     System.out.println("The configuration is: " + configuration1); 
    } 
} 

出力は

Enter number of test cases: 
3 
Enter the configuration: 
10 
The configuration is: 10 
Enter the configuration: 
20 
The configuration is: 20 
Enter the configuration: 
30 
The configuration is: 30 
関連する問題