Write a program to create two SDA to store names and marks of 25 students.Then display the name of the students who secured more than 90 as per their marks in descending order. And also display how many such students found.
package com.task;
public class Main {
public static void main(String[] args) {
String[] names = {"Jones","Williams","Beck","Stuart","Smith",
"Wolf","Ivanov","Randal","Scott","Perry",
"Steve","Mason","Gemme","Johnson","Peterson",
"O'Hara","O'Neil","Gibbson","Suane","Jameson",
"Klinton","Trump","Stevenson","Jackson","Sommerset"};
Integer[] marks = {37,86,95,76,65,
45,87,96,97,90,
84,86,81,83,82,
76,76,76,75,74,
85,76,85,91,55};
int n = marks.length;
int temp;
String tempStr;
for(int i = 0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(marks[j-1] < marks[j]){
//swap elements
temp = marks[j-1];
tempStr = names[j-1];
marks[j-1] = marks[j];
names[j-1] = names[j];
marks[j] = temp;
names[j] = tempStr;
}
}
}
int cnt = 0;
for (int i = 0; i < marks.length; i++) {
if (marks[i] > 90) {
cnt++;
System.out.println(names[i]);
}
}
System.out.println("Total: " + cnt);
}
}
Comments
Leave a comment