Write down a program in Java with arrays.
Answers
Answer:
Let us see the example of print the elements of Java array using the for-each loop.
1.//Java Program to print the array elements using for-each loop.
2.class Testarray1{
3.public static void main(String args[]){
4.int arr[]={33,3,4,5};
5.//printing array using for-each loop.
6.for(int i:arr)
7.System.out.println(i);
8.}}
➝ { public static void main(String[] args)
{int n, res,i,j=0;
Scanner s = new Scanner(System.in);
System.out.print("8:");
n = s.nextInt(1,2,3,4,6,7,8,9);
int array[] = new int[n];
int rev[] = new int[n];
System.out.println("Enter "+n+" elements ");
for( i=0; i < 8; i++)
{A1 :/A2
array[i] = s.nextInt(1,2,3,4,6,7,8,9);
}
System.out.println("Reverse of an array is :");
for( i=n;i>0 ; i--,j++)
{A2:/A1
rev[j] = array[i-1];
System.out.println(rev[j]);}}}
A1_1234___
__⬜⬜⬜⬜_
↑↓↑↓↑↓↑↓↑
A2_⬜⬜⬜⬜__
___6789__
+
A2_1234___
__⬜⬜⬜⬜_
↑↓↑↓↑↓↑↓↑
A1_⬜⬜⬜⬜__
___6789__
___________________________________