pTutorial

New way to learn Programming

Java array example source code

Following Java program print the array from the last. We use simply for loop to doing this task. Let suppose your array is

25 5 10 15

Then the output is
15
10
5
25

Java print array from last

// java program to print array from the last
import java.util.Scanner;
public class PrintArrayFromLast {
    public static void main(String[] args) 
    {
    int n;
    Scanner uk=new Scanner(System.in);
    System.out.println("Enter the number of element");
    n = uk.nextInt();
    int z[]=new int[n];
    
    System.out.println("Enter "+ n +"  numbers");
    for(int l=0;l<z.length;l++){
        z[l]= uk.nextInt();
    }
    System.out.println("OuTput:");
    System.out.println("Array element from last are :");
    for(int l=z.length-1;l>=0;l--)
    {
        System.out.println(z[l]);
   	}
    }
}


Output

Enter the number of element
3
Enter 3  numbers
1
2
3
OuTput:
Array element from last are :
3
2
1

See Also


QUOTES OF THE DAY

Crafty men condemn studies, simple men admire them, and wise use them.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER