Posted by: Sourav | August 4, 2015

Array of objects example in Java


import java.io.*;
class arr{
int benmarks;
int hismarks;

}
class sample{
public static void main(String args[]) throws IOException
{
arr[] account=new arr[5];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int n=0;
while(n<5)
{
account[n]=new arr();

System.out.println(“Enter Number for student “+n+” in Bengali”);
account[n].benmarks=Integer.parseInt(br.readLine());

System.out.println(“Enter Number for student “+n+” in History”);
account[n].hismarks=Integer.parseInt(br.readLine());

n++;

}
n=0;
while(n<5)
{
//account[n]=new arr();
System.out.println(“Student Number”+” |  “+”Marks Bengali” +” | “+”Marks History”);
System.out.println();
System.out.println();

System.out.println(”    “+n+”          |  “+account[n].benmarks+”            | “+account[n].hismarks );

//System.out.println(”                              “+account[n].benmarks+”                          “+account[n].hismarks);
//account[n].hismarks=Integer.parseInt(br.readLine());

System.out.println();
System.out.println();
n++;

}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: