Advertisement
MadCortez

Untitled

Sep 27th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2. class MyClass {
  3.     public static void main(String[] args){
  4.         final int MIN_SIZE = 1;
  5.         final int MAX_SIZE = 10001;
  6.         final int MIN_VALUE = -1000000001;
  7.         final int MAX_VALUE = 1000000001;
  8.         System.out.println("Данная программа 'переворачивает' заданную последовательность");
  9.         boolean isNotValid = true;
  10.         int n;
  11.         int temp;
  12.         System.out.print("Введите кол-во элементов последовательность в диапазоне " + (MIN_SIZE + 1) + ".." + (MAX_SIZE - 1) + ": ");
  13.         Scanner in = new Scanner(System.in);
  14.         do {
  15.             n = Integer.parseInt(in.nextLine());
  16.             if (n > MIN_SIZE && n < MAX_SIZE)
  17.                 isNotValid = false;
  18.             else
  19.                 System.out.println("Введите кол-во элементов последовательности в заданном диапазоне");
  20.         } while (isNotValid);
  21.         int a[] = new int[n];
  22.         System.out.println("Введите элементы последовательности в диапазоне " + (MIN_VALUE + 1) + ".." + (MAX_VALUE - 1) + " через Enter:");
  23.         for(int i = 0; i < n; i++) {
  24.             isNotValid = true;
  25.             do {
  26.                 System.out.print("Введите " + (i + 1) + "-й элемент: ");
  27.                 a[i] = Integer.parseInt(in.nextLine());
  28.                 if (a[i] > MIN_VALUE && a[i] < MAX_VALUE)
  29.                     isNotValid = false;
  30.                 else
  31.                     System.out.println("Введите элемент последовательности в заданном диапазоне");
  32.             } while(isNotValid);
  33.         }
  34.         for (int i = 0; i < n / 2; i++) {
  35.             temp = a[i];
  36.             a[i] = a[n - i - 1];
  37.             a[n - i - 1] = temp;
  38.         }
  39.         System.out.println("'Перевёрнутая' последовательность: ");
  40.         for (int i = 0; i< n; i++) {
  41.             System.out.print(a[i]+" ");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement