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. String buffer[];
  13. Scanner scan = new Scanner(System.in);
  14. System.out.println("Enter Size: ");
  15. int num = scan.nextInt();
  16.  
  17. buffer = new String[num];
  18. scan.nextLine();
  19. String read = scan.nextLine();
  20. for(int i=0; i<buffer.length; i++) {
  21. if(read.equals("quit")) {
  22. break;
  23. } else {
  24. buffer[i] = read;
  25. }
  26. read = scan.nextLine();
  27. }
  28.  
  29. for(int k=buffer.length -1; k>=0; k--) {
  30. System.out.println(buffer[k]);
  31. }
  32. }
  33.  
  34. }
Success #stdin #stdout 0.14s 321088KB
stdin
2
akash
singh
quit
stdout
Enter Size: 
singh
akash