fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("Введите число строк: ");
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. sc.nextLine(); // прочитать всё до конца строки (т.о. пропустить \n в буфере чтения
  16. System.out.println(" n = " + n+"\n");
  17. String[] starray = new String[n];
  18.  
  19. for(int i=0;i<n;i++)
  20. {
  21. //System.out.println("\nВведите строку:");
  22. starray[i]=sc.nextLine();
  23. }
  24. System.out.println("Введённые строчки в порядке их ввода:::");
  25. for(int i=0;i<n;i++)
  26. {
  27. System.out.println(starray[i]);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.06s 2184192KB
stdin
6
stroka first
stroka 2
stroka3 
stroka4 4 4 4 
5 stroka 5
6 str-6 6 6 6 6
7-th line
stdout
Введите число строк: 
 n = 6

Введённые строчки в порядке их ввода:::
stroka first
stroka 2
stroka3 
stroka4 4 4 4 
5 stroka 5
6 str-6 6 6 6 6