Sunday, August 12, 2012

Java program to read and print n student names


import java.io.*;
class stringop1
{
String s[];
int n;
stringop1(int x)
{
s= new String[x];
n=x;
}
void get()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<n;i++)
{
System.out.print("\nName of student "+(i+1)+" : ");
s[i]=br.readLine();
}
}
void disp()
{
System.out.print("\nThe Entered names are : ");
for(int i=0;i<n;i++)
System.out.print("\nName "+(i+1)+" : " +s[i]);
}
public static void main(String[] args)throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter the no.of students : ");
int x=Integer.parseInt(b.readLine());
stringop1 s=new stringop1(x);
s.get();
s.disp();
}
}

0 comments:

Post a Comment