Write a class called ArrayRecap which has a main method Insi

Write a class called ArrayRecap which has a main method. Inside the main method: - Create an array of integers of size 10 called intArray - Using a for loop, repeat the following 10 times o Ask the user to enter an integer o Store the number into the intArray - SOP the contents of this array using Arrays.toString ( You will need to import a class!) - Write a second loop that displays the values in the intArray in the opposite order from which they were entered and computes their decimal average. - Display the decimal average of the numbers entered.

Solution

public class ReverseArray {

   public static void main(String[] args) {
      
       int arr[]=new int[10];
       int j=0;
       int k;
       int temp;
       int a,b;
       double decimaval=0;
       Scanner read =new Scanner(System.in);
      
       for(int i=0;i<10;i++)
       {
           j=i+1;
           System.out.println(\"Please enter \"+ j + \" value\");
           arr[i]=read.nextInt();
          
       }
       System.out.println(\"Entered values::\");
       for(int i=0;i<10;i++)
       {
           System.out.println(\"\"+arr[i]);
          
       }
       System.out.println(\"Reverse values::\");
       j = 10 - 1; // now j will point to the last element
   int i = 0; // and i will point to the first element
       int t=0;
   while(i<j)
   {
   temp = arr[i];
   arr[i] = arr[j];
   arr[j] = temp;
   i++;
   j--;
   }
         
   System.out.print(\"Now the Reverse of Array is : \ \");
   for(i=0; i<10; i++)
   {
       t+=arr[i];
   System.out.print(arr[i]+ \" \");
   }   
   decimaval=t/10;
   System.out.println(\"\");
       System.out.println(\"decimal value:::::::\"+decimaval);
   }
}

Expected output
===============

Please enter 1 value

1
Please enter 2 value

2
Please enter 3 value

3
Please enter 4 value

4
Please enter 5 value

5
Please enter 6 value

6
Please enter 7 value

7
Please enter 8 value

8
Please enter 9 value

9
Please enter 10 value

10
Entered values::
1
2
3
4
5
6
7
8
9
10
Reverse values::
Now the Reverse of Array is :
10 9 8 7 6 5 4 3 2 1
decimal value:::::::5.0

Write a class called ArrayRecap which has a main method. Inside the main method: - Create an array of integers of size 10 called intArray - Using a for loop, re
Write a class called ArrayRecap which has a main method. Inside the main method: - Create an array of integers of size 10 called intArray - Using a for loop, re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site