fork download
  1. class ex00 {
  2. public static void main(String[] args) throws Exception {
  3. // あとで追加
  4. System.out.print("ファイル名を入力してください:");
  5. String d = br.readLine();
  6. file f = new file(d);
  7. System.out.println(f.getAllData());
  8.  
  9. System.out.println("行数を入力してください");
  10. int n = Integer.parseInt(br.readLine());
  11. System.out.println(f.readLine(n));
  12.  
  13. f.sort();
  14. System.out.println(f.getAllData());
  15. }
  16. }
  17.  
  18. class file {
  19. String file_name;
  20. String[] lines = new String[10];
  21.  
  22. file(String _filename) throws Exception {
  23. FileInputStream fis = new FileInputStream(_filename);
  24. int i = 0;
  25. while (br.ready()) {
  26. lines[i] = br.readLine();
  27. i++;
  28. }
  29. }
  30.  
  31. public String readLine(int n) {
  32. return lines[n];
  33. }
  34.  
  35. public String getAllData() {
  36. String result = "";
  37. for (int i = 0; i < lines.length; i++) {
  38. result += lines[i] + "\n";
  39. }
  40. return (result);
  41. }
  42.  
  43. public void sort() {
  44. Arrays.sort(lines, new Comparator<String>() {
  45. public int compare(String o1, String o2) {
  46. return Integer.compare(o1.length(), o2.length());
  47. }
  48. });
  49. }
  50. }
  51.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty