| 1. |
Wap in Java to accept marks of 10 subjects of a student in an integer array and display them from highest to loowest marks along with the students name. Use selection sort technique for arranging the marks. |
|
Answer» import JAVA . util . *; class PRO { PUBLIC static void main(String args[]) { Scanner sc=new Scanner(System . in); int marks[]=new int[10]; for(int i=0;i<10;i++) { System . out . println("Enter the marks"); marks[i]=sc . nextInt(); } for(int i=0;i<10;i++) { for(int j=i;j<10;j++) { if(marks[i]>marks[j]) { int temp=marks[i]; marks[i]=marks[j]; marks[j]=temp; } } } System . out . println("Highest marks = "+marks[0]); System . out . println("Highest marks = "+marks[9]); } } |
|