Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[]args)
- {
- int dlina, polDliny, i, peremen;
- int[] massiv;
- boolean isInCorrect;
- dlina = 0;
- Scanner scan = new Scanner(System.in);
- System.out.print("The program reverses the array.\n");
- System.out.print("Enter array length: ");
- do
- {
- isInCorrect = false;
- try {
- dlina = Integer.parseInt(scan.next());
- }
- catch (NumberFormatException e) {
- System.out.print("Symbols have been entered. Enter the number: ");
- isInCorrect = true;
- }
- if ((!isInCorrect) && (dlina == 0) || (dlina < 0))
- {
- System.out.print("A negative value or zero was entered. Enter a valid
- value: ");
- isInCorrect = true;
- }
- } while (isInCorrect);
- massiv = new int[dlina];
- System.out.print("Enter array members: ");
- for (i = 0; i < dlina; i++) {
- do
- {
- isInCorrect = false;
- try {
- massiv[i] = Integer.parseInt(scan.next());
- }
- catch (NumberFormatException e) {
- System.out.print("Symbols have been entered. Enter the number:
- ");
- isInCorrect = true;
- }
- } while (isInCorrect);
- }
- polDliny = dlina / 2;
- for (i = 0; i < polDliny; i++) {
- peremen = massiv[i];
- massiv[i] = massiv[dlina - i - 1];
- massiv[dlina - i - 1] = peremen;
- }
- for (i = 0; i < dlina; i++) {
- System.out.print(massiv[i]);
- System.out.print(" ");
- }
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement