Q:

(Reverse the numbers entered) Write a program that reads ten integers and displays them in the reverse of the order in which they were read

0

(Reverse the numbers entered) Write a program that reads ten integers and displays them in the reverse of the order in which they were read.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class exc {
	public static void main(String[] args) {
		int[] array = new int[10];

		// Prompt the user to enter ten integers
		System.out.print("Enter ten integers: ");

		// fill the array
		fill(array);

                int[] reversedArray = new int[10];

// Display integers in reverse order
		for (int i = array.length - 1; i >= 0; i--)
                {
                    reversedArray[i]=array[i];
                    System.out.print(reversedArray[i] + " ");
                }
                System.out.println();
	}

	/** Method fill */
	public static void fill(int[] array) {
		Scanner input = new Scanner(System.in);
		for (int i = 0; i < array.length; i++) 
			array[i] = input.nextInt();
	}   
}

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Reverse the numbers entered) Write a program that reads ten integers and displays
them in the reverse of the order in which they were read. 
*/
import java.util.Scanner;

public class Exercise_07_02 {
	/** Main Method */
	public static void main(String[] args) {
		int[] array = new int[10];

		// Prompt the user to enter ten integers
		System.out.print("Enter ten integers: ");

		// fill the array
		fill(array);

		// Display integers in reverse order
		for (int i = array.length - 1; i >= 0; i--)
			System.out.print(array[i] + " ");
		System.out.println();
	}

	/** Method fill */
	public static void fill(int[] array) {
		Scanner input = new Scanner(System.in);
		for (int i = 0; i < array.length; i++) 
			array[i] = input.nextInt();
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (2)

Similar questions


need a help?


find thousands of online teachers now