Advertisement
Asphorm

Java Fehler

Jun 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class ReadAndQuicksort {
  5. public static void main(String[] args) {
  6.  
  7. try {
  8. File file1 = new File("daten_org.txt");
  9. File file2 = new File("daten_sort.txt");
  10. File file3 = new File("array_1.txt");
  11. File file4 = new File("array_2.txt");
  12. file2.createNewFile();
  13. file3.createNewFile();
  14. file4.createNewFile();
  15.  
  16. Scanner scanner = new Scanner(file1);
  17. Scanner scr1 = new Scanner(file3);
  18. Scanner scr2 = new Scanner(file4);
  19.  
  20. PrintStream prs = new PrintStream(file2);
  21. PrintStream prs1 = new PrintStream(file3);
  22. PrintStream prs2 = new PrintStream(file4);
  23.  
  24. int[] arr = new int[100];
  25.  
  26. for(int i = 0; i < 100; i++) {
  27. arr[i] = scanner.nextInt();
  28. }
  29. Arrays.sort(arr);
  30. for(int i = 0; i < 100; i++) {
  31. prs1.print(arr[i] + " ");
  32. }
  33.  
  34. for(int i = 100; i < 165; i++) {
  35. arr[i-100] = scanner.nextInt();
  36. }
  37. Arrays.sort(arr);
  38. for(int i = 100; i < 165; i++) {
  39. prs2.print(arr[i-100] + " ");
  40. }
  41.  
  42. int a = 0, b = 0;
  43. boolean bA = true, bB = true;
  44.  
  45. for(int i = 0; i < 165; i++) {
  46. if(bA) a = scr1.nextInt();
  47. if(bB) b = scr2.nextInt();
  48.  
  49. if(a < b) {
  50. prs.print(a + " ");
  51. bA = true;
  52. bB = false;
  53. }
  54. if(a > b) {
  55. prs.print(b + " ");
  56. bA = false;
  57. bB = true;
  58. }
  59. if(a == b) {
  60. prs.print(a + " " + b + " ");
  61. bA = true;
  62. bB = true;
  63. i++;
  64. }
  65. }
  66.  
  67. delete(file3);
  68. delete(file4);
  69.  
  70. prs.close();
  71. prs1.close();
  72. prs2.close();
  73. } catch (IOException e) {}
  74.  
  75. System.out.println();
  76. System.out.println("ERFOLGREICH: Zahlen sortiert.");
  77. }
  78. }
  79.  
  80. ----------------------------------------------------------------------------------------------------------
  81.  
  82. Exception in thread "main" java.util.NoSuchElementException
  83. at java.util.Scanner.throwFor(Scanner.java:862)
  84. at java.util.Scanner.next(Scanner.java:1485)
  85. at java.util.Scanner.nextInt(Scanner.java:2117)
  86. at java.util.Scanner.nextInt(Scanner.java:2076)
  87. at ReadAndQuicksort.main(ReadAndQuicksort.java:47)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement