2016-11-11 3 views
-4

この問題の解決方法を教えていただけますか?Javaで名前を印刷しますか?

スキャナスキャナ=新しいスキャナ(System.in);

package Exercise2501; 

    import java.util.Scanner; 

    public class Friends 
    { 

     public static void main(String[] args) 
     { 

      Scanner scanner = new Scanner(System.in); 
      System.out.println("How many names do you want to enter?"); 
      int number = scanner.nextInt(); 
      for (int i = 0; i < number; i++) 
      { 
      System.out.println("Type a few names. "); 
      String names = scanner.nextLine(); 
      } 
      String names = scanner.nextLine(); 
      System.out.println(names); 


     } 

    } 
+0

uがrequire..Your質問はuが私はそれが私に尋ねるコードを実行しようとすると、印刷したいどのように多くの名詳細 –

+0

に与え、そしてちょうど版画「何をclear.canされていませんか数回入力してください " – 3au0

+0

ループの前に行を移動 – Venkat

答えて

0
package Exercise2501; 
    import java.util.Scanner; 

    public class Friends { 

    public static void main(String[] args) { 

     Scanner scanner = new Scanner(System.in); 
     //Get the number of entries 
     System.out.println("How many names do you want to enter?"); 
     int number = scanner.nextInt(); 
     //create an array with that number 
     String names[] = new names[number]; 
     //Ask the user to enter the Names 
     System.out.println("Type a few names. "); 
     //Store the names in the array 
     for (int i = 0; i < number; i++) 
     { 
      names[i] = scanner.nextLine(); 
     } 
     //Do the remaining you want 
    } 

    } 
関連する問題