Page 414 - CA_Blue( J )_Class10
P. 414
class Result{
public static void main() {
Scanner sc= new Scanner(System.in);
int n,i,total=0;
double avg=0.0;
System.out.print("Number of students: ");
n = sc.nextInt();
int roll[] = new int[n];
String name[] = new String[n];
int m1[] = new int[n];
int m2[] = new int[n];
int m3[] = new int[n];
for (i = 0; i < n; i++) {
System.out.print("Enter Roll number: ");
roll[i] = sc.nextInt();
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Marks 1: ");
m1[i] = sc.nextInt();
System.out.print("Enter Marks 2: ");
m2[i] = sc.nextInt();
System.out.print("Enter Marks 3: ");
m3[i] = sc.nextInt();
total = m1[i] + m2[i] + m3[i];
avg = total / 3.0;
if(avg >= 85 && avg <= 100)
System.out.println("EXCELLENT");
else if(avg >= 75)
System.out.println("DISTINCTION");
else if(avg >= 60)
System.out.println("FIRST CLASS");
else if(avg >= 40)
System.out.println("PASS");
else
System.out.println("POOR");
}
}
}
21. Write a program to input twenty names in an array. Arrange these names in descending order of alphabets, using the bubble
sort technique. [2015]
Ans. import java.util.*;
class sorting{
public static void main() {
Scanner sc= new Scanner(System.in);
String n[] = new String[20];
int i,j;
String temp;
System.out.println("Enter 20 names:");
for(i = 0; i < 20; i++)
n[i] = sc.next();
for(i = 0; i < 19; i++)
{ for(j = 0; j < 19 - i; j++)
{ if(n[j].compareToIgnoreCase(n[j + 1]) < 0)
{ temp = n[j];
n[j] = n[j + 1];
n[j + 1] = temp;
412412 Touchpad Computer Applications-X

