[go: up one dir, main page]

0% found this document useful (0 votes)
5 views1 page

Array 4

The document contains a Java program that reverses the elements of an array. It initializes an array with values 1 to 5, prints the original array, and then prints the reversed array. The output demonstrates the original and reversed arrays clearly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Array 4

The document contains a Java program that reverses the elements of an array. It initializes an array with values 1 to 5, prints the original array, and then prints the reversed array. The output demonstrates the original and reversed arrays clearly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a program to reverse the elements present in an

array.

Public class ReverseArray {

Public static void main(String[] args) {

Int[] arr = {1, 2, 3, 4, 5};

System.out.print(“Original Array: “);

For (int I : arr) {

System.out.print(I + “ “);

System.out.print(“\nReversed Array: “);

For (int I = arr.length – 1; I >= 0; i--) {

System.out.print(arr[i] + “ “);

Output
Original Array: 1 2 3 4 5
Reversed Array: 5 4 3 2 1

You might also like