Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would you create a Java program, using Scanner.in, that calls a method to as

ID: 3634389 • Letter: H

Question

How would you create a Java program, using Scanner.in, that calls a method to ask the user for 10 integers and then calls another method that prints those 10 integers to the screen in reverse order (use an array; you may not use global variables). In this program, the length operator will report the number of elements in an array (or you can pass the number of elements to your method via a parameter). If the array name is: numbers, then the number of elements in the array is stored into the int variable size by: size = numbers.length.

Explanation / Answer

public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);

// read in 10 integers
int[] numbers = new int[10];

for(Int i = 0; i < numbers.length; i++)
{
System.out.print("Enter number "+(i+1)+": ");
numbers[i] = kb.nextInt();
}

// print in reverse order
printReverse(numbers);
}

public static void printReverse(int[] array)
{
for(int i = array.length-1; i >= 0; i--)
System.out.print(array[i]+" ");
System.out.println();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote