Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int[] enterarr(int numb, int n) {
- int[] arr = new int[n];
- int temp = 0;
- boolean invalidinput = false;
- do {
- boolean iscorrect = false;
- try {
- BufferedReader input = new BufferedReader(new FileReader("D:\\input.txt"));
- String text = input.readLine();
- for (int i = 0; i < numb + 1; i++) {
- text = input.readLine();
- }
- String[] arra = text.split(" ");
- for (int i = 0; i < n; i++) {
- do {
- System.out.print("Enter the " + (i + 1) + " member of sequence " + (numb + 1) + " they mast not be the same ");
- arr[i] = Integer.parseInt(arra[i]);
- System.out.println(arr[i] + " ");
- iscorrect = enter(arr[i], 200000, -200000);
- for (int j = 0; j < i; j++) {
- if (arr[j] == arr[i]) {
- temp++;
- }
- }
- if (temp > 1) {
- iscorrect = true;
- System.out.println("This is a mistake members are same! Please enter again!");
- } else {
- iscorrect = false;
- }
- temp = 0;
- } while (iscorrect);
- }
- input.close();
- } catch (FileNotFoundException e) {
- System.out.println("A file with the same name was not found");
- invalidinput = true;
- } catch (IOException e) {
- System.out.println("This file cannot be opened");
- invalidinput = true;
- } catch (NumberFormatException e) {
- System.out.println("Error! File contains invalid data");
- invalidinput = true;
- }
- } while (invalidinput);
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement