Sunday, 12 March 2023

2. Write a program to create an array to store 5 integer values. Also initialize the array with 5 numbers and display the array Elements in reverse order


class Program2
{
    public static void main(String args[])
    {
        int arr[] = new int[] {1,2,3,4,5};
       
        System.out.print("array values: ");
        for(int i=0; i<arr.length; i++)
        {
            System.out.print(arr[i] + " ");
        }
       
        System.out.println("\nreverse of array: ");
        for(int i = arr.length-1; i>=0; i--)
        {
            System.out.print(arr[i] + " ");
        }
    }
}


 

No comments:

Post a Comment

python programs

1. sum of two number