Advertisement
nikitaxe132

Untitled

Oct 29th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1.  static int[] enterarr(int numb, int n) {
  2.         int[] arr = new int[n];
  3.         int temp = 0;
  4.         boolean invalidinput = false;
  5.         do {
  6.             boolean iscorrect = false;
  7.             try {
  8.                 BufferedReader input = new BufferedReader(new FileReader("D:\\input.txt"));
  9.                 String text = input.readLine();
  10.                 for (int i = 0; i < numb + 1; i++) {
  11.                     text = input.readLine();
  12.                 }
  13.                 String[] arra = text.split(" ");
  14.                 for (int i = 0; i < n; i++) {
  15.                     do {
  16.                         System.out.print("Enter the " + (i + 1) + " member of sequence " + (numb + 1) + " they mast not be the same ");
  17.                         arr[i] = Integer.parseInt(arra[i]);
  18.                         System.out.println(arr[i] + " ");
  19.                         iscorrect = enter(arr[i], 200000, -200000);
  20.                         for (int j = 0; j < i; j++) {
  21.                             if (arr[j] == arr[i]) {
  22.                                 temp++;
  23.                             }
  24.                         }
  25.                         if (temp > 1) {
  26.                             iscorrect = true;
  27.                             System.out.println("This is a mistake members are same! Please enter again!");
  28.                         } else {
  29.                             iscorrect = false;
  30.                         }
  31.                         temp = 0;
  32.                     } while (iscorrect);
  33.                 }
  34.                 input.close();
  35.             } catch (FileNotFoundException e) {
  36.                 System.out.println("A file with the same name was not found");
  37.                 invalidinput = true;
  38.             } catch (IOException e) {
  39.                 System.out.println("This file cannot be opened");
  40.                 invalidinput = true;
  41.             } catch (NumberFormatException e) {
  42.                 System.out.println("Error! File contains invalid data");
  43.                 invalidinput = true;
  44.             }
  45.         } while (invalidinput);
  46.         return arr;
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement