Advertisement
MadCortez

Untitled

Sep 24th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 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.         int a[] = new int[MAX_SIZE];
  13.         System.out.print("Введите кол-во элементов последовательность в диапазоне " + (MIN_SIZE + 1) + ".." + (MAX_SIZE - 1) + ": ");
  14.         Scanner in = new Scanner(System.in);
  15.         do {
  16.             n = Integer.parseInt(in.nextLine());
  17.             if (n > MIN_SIZE && n < MAX_SIZE)
  18.                 isNotValid = false;
  19.             else
  20.                 System.out.println("Введите кол-во элементов последовательности в заданном диапазоне");
  21.         } while (isNotValid);
  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.                 a[i] = Integer.parseInt(in.nextLine());
  27.                 if (a[i] > MIN_VALUE && a[i] < MAX_VALUE)
  28.                     isNotValid = false;
  29.                 else
  30.                     System.out.println("Введите элемент последовательности в заданном диапазоне");
  31.             } while(isNotValid);
  32.         }
  33.         for (int i = 0; i < n / 2; i++) {
  34.             temp = a[i];
  35.             a[i] = a[n - i - 1];
  36.             a[n - i - 1] = temp;
  37.         }
  38.         System.out.println("'Перевёрнутая' последовательность: ");
  39.         for (int i = 0; i< n; i++) {
  40.             System.out.print(a[i]+" ");
  41.         }
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement