Write a program in java to accept an integer array with n number of elements. Reverse each elements of the array. Display the original array ,array after reversing each element in the original order and in the reverse order.
Answers
Explanation:
Reversing an array in java can be done in three simple methods.
Reversing an array in java can be done in three simple methods.Examples:
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:(i) Take input the size of array and the elements of array.
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:(i) Take input the size of array and the elements of array.(ii) Consider a function reverse which takes the parameters-the array(say arr) and the size of the array(say n).
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:(i) Take input the size of array and the elements of array.(ii) Consider a function reverse which takes the parameters-the array(say arr) and the size of the array(say n).(iii) Inside the function, a new array (with the array size of the first array, arr) is initialized. The array arr[] is iterated from the first element and each element of array arr[] is placed in the new array from the back, i.e, the new array is iterated from its last element.
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:(i) Take input the size of array and the elements of array.(ii) Consider a function reverse which takes the parameters-the array(say arr) and the size of the array(say n).(iii) Inside the function, a new array (with the array size of the first array, arr) is initialized. The array arr[] is iterated from the first element and each element of array arr[] is placed in the new array from the back, i.e, the new array is iterated from its last element.(iv) In this way, all the elements of the array arr[] are placed reversely in the new array.
Reversing an array in java can be done in three simple methods.Examples:Input : 1, 2, 3, 4, 5Output :5, 4, 3, 2, 1Input : 10, 20, 30, 40Output : 40, 30, 20, 10The first method is as follows:(i) Take input the size of array and the elements of array.(ii) Consider a function reverse which takes the parameters-the array(say arr) and the size of the array(say n).(iii) Inside the function, a new array (with the array size of the first array, arr) is initialized. The array arr[] is iterated from the first element and each element of array arr[] is placed in the new array from the back, i.e, the new array is iterated from its last element.(iv) In this way, all the elements of the array arr[] are placed reversely in the new array.(v) Further, we can iterate through the new array from the beginning and print the elements of the array.
pls mark as Brainliast
Answer:
import java.util.*;
class Reverse
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of n");
int n=sc.nextInt();
int original[]=new int[n];
System.out.println("Enter "+n+" integers");
for(int i=0;i<n;i++)
{
original[i]=sc.nextInt();
}
int reverse[]=new int[n];
for(int j=0;j<original.length;j++)
{
int temp=original[j];
int rev=0;
while(original[j]!=0)
{
int digit=temp%10;
rev=(rev*10)+digit;
temp=temp/10;
}
reverse[j]=rev;
}
System.out.println("Original array");
for(int k=0;k<original.length;k++)
{
System.out.println(original[k]);
}
System.out.println("Final array");
for(int l=0;l<original.length;l++)
{
System.out.println(reverse[l]);
}
}
}