Wednesday, September 4, 2019

BlueJ Program Using Numeric And String Array On Marks

This BlueJ Program involves both numeric and String type array. The BlueJ program will take name and marks of ‘n’ students and display the name of students with highest and lowest marks.


import java.util.Scanner;
class Star
{
int marks[];
String names[];
int i,j,n,temp;
Scanner sc=new Scanner(System.in);
public void take()
{
System.out.print("\nHow many students: ");
n=sc.nextInt();
marks=new int[n];
names=new String[n];
for(i=0;i< n;i++)
{
System.out.print("\nEnter name of student:");
names[i]=sc.next();
System.out.print("\nEnter Corresponding Marks: ");
marks[i]=sc.nextInt();
}
}
public void sort()
{
 String s;
 for(i=0;i< n-1;i++)
 {
      for(j=i+1;j< n;j++)


      {
           if(marks[i]< marks[j])
           {
                temp=marks[i];
                marks[i]=marks[j];
                marks[j]=temp;
               
                s=names[i];
                names[i]=names[j];
                names[j]=s;
            }
        }
    }
}
public void show()
{
System.out.print("\nStudent With Highest Marks: "+names[0]);
System.out.print("\nStudent With Lowest Marks: "+names[n-1]);
}

public static void main(String args[])
{
 Star ob=new Star();
 ob.take();
 ob.sort();
 ob.show();
}
}

Related Post: BlueJ Programs on Numeric Array
                        BlueJ Programs on String/Sentence

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner