Search This Blog

program in java to input three student details and print them in alphabetcal order

//source code:
import java.util.*;
class student
{
String name=new String();
int rollnumber;
float marks;
Scanner s=new Scanner(System.in);
void input()
{
System.out.println("Enter Name");
name=s.nextLine();
System.out.println("Enter Rollnumber");
rollnumber=s.nextInt();
System.out.println("Enter Marks");
marks=s.nextFloat();
System.out.println("*********************************");
}
void show()
{
System.out.println("Name :"+name);
System.out.println("Rollnumber :"+rollnumber);
System.out.println("Marks :"+marks);
System.out.println("*********************************");
}
}
class Order extends student
{
void sort(student... st)
{
for(int i=0;i{

for(int j=0;j{
if((st[i].name).compareTo(st[j].name)<0 p="">  {
   String temp=st[i].name;
   st[i].name=st[j].name;
   st[j].name=temp;
   int temp1=st[i].rollnumber;
   st[i].rollnumber=st[j].rollnumber;
   st[j].rollnumber=temp1;
   float temp2=st[i].marks;
   st[i].marks=st[j].marks;
   st[j].marks=temp2;
  }
}}}}
class demo
{
public static void main(String[] args)
{
  System.out.println("Enter details of ten students");
  student s1=new student();
   student s2=new student();
    student s3=new student();
    s1.input();
    s2.input();
    s3.input();
 
   Order ob=new Order();
   ob.sort(s1,s2,s3);

   s1.show();
   s2.show();
   s3.show();
}
}  
OUTPUT:

2 comments:

leave a comment here