Basic example using Arrays in Java


Here is the simple program for printing basic example using Arrays in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class arrays
{
  public static void main(String args[])
  {
   //a[100]
	int i,n;
	System.out.print("\nEnter The Limit ");
	Scanner in =new Scanner(System.in);
	n=in.nextInt();
	int a[] =new int[n]; 
	for(i=0;i<n;i++)
	{
	  System.out.print("\nEnter The Value Of A : ");
	  a[i]=in.nextInt();
	}
	funs o =new funs();
	o.add(a);
	}
}
class funs
{
  private int tot,avg;
  public void add(int []a)
  {
  	for(int i=0;i<a.length;i++)
  	{
  	  System.out.print("\n"+a[i]);
  	  tot+=a[i];
  	}
    System.out.print("\n___________");
    System.out.print("\nTotal   : "+tot);
    avg=tot/a.length;
    System.out.print("\nAverage : "+avg);
  }
}	
To download raw file Click Here

Output

Enter The Limit  5
Enter The Value Of A : 20
Enter The Value Of A : 45
Enter The Value Of A : 32
Enter The Value Of A : 65
Enter The Value Of A : 34
20
45
32
65
34
___________
Total   : 196
Average : 39


Learn All in Tamil © Designed & Developed By Tutor Joes