Thursday 12 June 2014

Program to use array in class

import javax.swing.JOptionPane;

class array
{
int i;
int []a= new int[5];

public void in()
{
System.out.print("enter array elements");
for(i=0; i<5; i++)
a[i]=Integer.parseInt(JOptionPane.showInputDialog(" "));
}
public void out()
{
for(i=0; i<5; i++)
System.out.print(" "+a[i]);
}
}
public class arrayinclass {

public static void main(String[] args) {
array w=new array();
w.in();
w.out();

}

}

output:
enter array elements 1
2
3
4
5
1 2 3 4 5

No comments:

Post a Comment

SAY HELLO!!