fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. String[] data = new String[1];
  6. int count = 0;
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. while (true) {
  10. System.out.print("> ");
  11. String line = scanner.nextLine();
  12.  
  13. if (line.equals("end")) {
  14. break;
  15. }
  16.  
  17. if (count >= data.length) {
  18. String[] tmp = new String[data.length * 2];
  19.  
  20. for (int i = 0; i < count; i++) {
  21. tmp[i] = data[i];
  22. }
  23.  
  24. data = tmp;
  25. }
  26.  
  27. data[count++] = line;
  28. }
  29.  
  30. bubblesort(data, 0, count);
  31.  
  32. for (int i = 0; i < count; i++) {
  33. System.out.println(data[i]);
  34. }
  35. }
  36.  
  37. public static void bubblesort(String[] data, int start, int last) {
  38. for (int i = last - 1; i > start; i--) {
  39. for (int j = start; j < i; j++) {
  40. if (data[j].compareTo(data[j + 1]) > 0) {
  41. swap(data, j, j + 1);
  42. }
  43. }
  44. }
  45. }
  46.  
  47. public static void swap(String[] data, int x, int y) {
  48. String tmp = data[x];
  49. data[x] = data[y];
  50. data[y] = tmp;
  51. }
  52. }
Runtime error #stdin #stdout #stderr 0.1s 380608KB
stdin
Standard input is empty
stdout
> 
stderr
Exception in thread "main" java.util.NoSuchElementException: No line found
	at java.util.Scanner.nextLine(Scanner.java:1585)
	at Main.main(Main.java:11)