Professional Documents
Culture Documents
Selection Sort
import java.io.*;
class SelectionSort
{int n,i;
int a[] = new int[100];
public SelectionSort(int nn) //parameterized constructor
{n=nn;
}
public void input() throws IOException //function accepting array elements
{BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter elements");
for(i=0;i<n;i++)
{a[i] = Integer.parseInt(br.readLine());
}}
public void display() //function displaying array elements
{System.out.println();
for(i=0;i<n;i++)
{System.out.print(a[i]+" ");
}}
public void sort() //function sorting array elements using selection sort
technique
{int j,temp,min;
for(i=0;i<n-1;i++)
{min =i;
for(j=i+1;j<n;j++)
{if(a[j]<a[min])
min =j;
}
if(min!=i)
{temp = a[i];
a[i] =a[min];
a[min] = temp;
}}}
public static void main(String args[]) throws IOException //main function
{SelectionSort x = new SelectionSort(5);
x.input();
System.out.print("Before sorting - ");
x.display();
System.out.print("After sorting - ");
x.sort();
x.display();
}}
Sample Output
Sample Output
Sample Output
Sample Output
Enter the lower range : 1
Enter the upper range : 200
The Twin Prime Numbers within the given range are :
(3,5) (5,7) (11,13) (17,19) (29,31) (41,43) (59,61) (71,73) (101,103) (107,109) (137,139) (149,151)
(179,181) (191,193) (197,199)
import java.io.*;
class FiboString
{
String x,y,z;
int n;
FiboString() // Constructor
{
x = "a";
y = "b";
z = "ba"; // mentioned in the question otherwise not required. z = "" is sufficient
}
void accept()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter the number of terms : ");
n = Integer.parseInt(br.readLine());
}
void generate()
{
System.out.print("\nThe Fibonacci String Series is : ");
if(n <= 1) // If no of terms is less than or equal to 1
System.out.print(x);
else // If no of terms is more than or equal to 2
{
System.out.print(x+", "+y);
for(int i=3; i<=n; i++)
{
z = y+x;
System.out.print(", "+z);
x = y;
y = z;
}
}
}
public static void main(String args[]) throws IOException
{
FiboString ob = new FiboString();
ob.accept();
ob.generate();
}
}
Sample Output
1) Enter
the
number
The Fibonacci String Series is : a, b
2) Enter the number of terms : 5
The Fibonacci String Series is : a, b, ba, bab, babba
of
terms
return true;
else
return false;
}
public static void main(String args[])throws IOException
{
MagicComposite_ISC2014 ob = new MagicComposite_ISC2014();
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter the lower limit(m) : ");
int m=Integer.parseInt(br.readLine());
System.out.print("Enter the upper limit(n) : ");
int n=Integer.parseInt(br.readLine());
int c=0;
if (m<n)
{
System.out.println("The Composite Magic Integers are: ");
for(int i=m; i<=n; i++)
{
if(ob.isComposite(i)==true && ob.isMagic(i)==true)
{
if (c==0) // Printing the first number without any comma
System.out.print(i);
else
System.out.print(", "+i);
c++;
}
}
System.out.println("nThe frequency of Composite Magic Integers is : "+c);
}
else
System.out.println("OUT OF RANGE");
}
}
Sample Output
import java.io.*;
class Keith
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number : "); //inputting the number
int n=Integer.parseInt(br.readLine());
int copy=n;
String s=Integer.toString(n);
int d=s.length(); //finding the number of digits (d) in the number
int arr[]=new int[n]; //array for storing the terms of the series
for(int i=d-1; i>=0; i--)
{
arr[i]=copy%10; //storing the digits of the number in the array
copy=copy/10;
}
int i=d,sum=0;
while(sum<n) //finding the sum till it is less than the number
{
sum = 0;
for(int j=1; j<=d; j++) //loop for generating and adding the previous 'd' terms
{
sum=sum+arr[i-j];
}
arr[i]=sum; //storing the sum in the array
i++;
}
/* When the control comes out of the while loop, either the
sum is equal to the number or greater than it */
if(sum==n) //if sum is equal to the number, then it is a Keith number
System.out.println("The number is a Keith Number");
else
System.out.println("The number is a not a Keith Number");
}}
Sample Output
Enter the number : 197
The number is a Keith Number
Enter the number : 14
The number is a Keith Number
Enter the number : 53
The number is a not a Keith Number
Sample Output
1. Enter a number : 15
1+2+3+4+5
4+5+6
7+8
2. Enter a number : 95
5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14
17 + 18 + 19 + 20 + 21
47 + 48
Sample Output
Example
Enter
any
word:
Word after removing repeated characters = Java
Example
Enter
any
word:
Word after removing repeated characters = isfun
1:
Jaaavvvvvvvvaaaaaaaaaaa
2:
iiiiiisssssfffffffffffffuunnnnn
import java.io.*;
class Smith
{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//function for finding sum of digits
int sumDig(int n)
{ int s=0;
while(n>0)
{ s=s+n%10;
n=n/10;
}
return s;
}
//function for generating prime factors and finding their sum
int sumPrimeFact(int n)
{ int i=2, sum=0;
while(n>1)
{ if(n%i==0)
{ sum=sum+sumDig(i); //Here 'i' is the prime factor of 'n' and we are finding its sum
n=n/i;
}
else
i++;
}
return sum;
}
public static void main(String args[]) throws IOException
{ Smith ob=new Smith();
System.out.print("Enter a Number : ");
int n=Integer.parseInt(br.readLine());
int a=ob.sumDig(n);// finding sum of digit
int b=ob.sumPrimeFact(n); //finding sum of prime factors
System.out.println("Sum of Digit = "+a);
System.out.println("Sum of Prime Factor = "+b);
if(a==b)
System.out.print("It is a Smith Number");
else
System.out.print("It is Not a Smith Number");
}}
Sample Output
1. Enter
Sum
Sum
of
It is a Smith Number
a
of
2. Enter
a
Sum
of
Sum
of
It is Not a Smith Number
3. Enter
Sum
Sum
of
It is a Smith Number
a
of
Prime
Number
Digit
:
=
Factor
Number
Digit
Prime
Prime
102
3
13
4937775
42
42
:
=
Factor
Number
Digit
94
13
13
:
Factor
Accept the sentence and reduce all the extra blank space between two words to
Accept a word from the user which is part of the sentence along with its
position number and delete the word and display the sentence
import java.io.*;
class RemoveWord_ISC2014
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter any sentence : "); // Inputting the sentence
String s = br.readLine();
s = s.toUpperCase(); // Converting the sentence into Upper Case
int l = s.length();
String ans=""; // String variable to store the final result
char last = s.charAt(l-1); // Extracting the last character
/* Checking whether the sentence ends with '.', '?' or a '!' or not */
if(last == '.' || last == '?' || last == '!')
{
String word[]=s.split("[.?! ]+"); // Saving the words in an array using split()
int c = word.length; // Finding the number of words
{
/* Skipping if the word to delete and the position matches */
if(word[i].equals(del)==true && i == x-1)
continue;
ans = ans + word[i] + " ";
}
System.out.print("Output : "+ans.trim()+last);
}
}
else
{
System.out.println("Invalid Input. End a sentence with either '.', '?' or '!'");
}
}
}
Output:
1. Enter any sentence : A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.
Enter
the
word
Enter the word position is the sentence : 6
to
delete
IS
WELL
##
Additionally the coded message is printed in blocks of six characters separated by spaces. The last
block might not contain six characters.
import java.io.*;
public class Decode_ISC2003
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Coded Text : "); // inputting coded text
String s = br.readLine();
int l = s.length();
s = s.toUpperCase(); // converting the coded text into Uppercase
s = s + " "; // adding a space at the end
else
{
System.out.print("Enter the Shift Value : ");
int shift = Integer.parseInt(br.readLine());
if(shift<1 || shift>26) // checking whether shift value is between 1 and 26
System.out.println("!!! Invalid Shift Value !!!");
else
{
int a, b;
a = a - 26;
if(ch1 != ' ')
dec = dec + (char)a; // finally adding the decoded character to the new String
}
System.out.println("Decoded Text : "+dec);
}
}}
Output:
Example
Enter
Coded
Enter
the
Decoded Text : ANOTHER WINNER
Text
Shift
Value
1:
UHINBYLKKQCHHYLKK
:
7
Example
Enter
Coded
Enter
the
Decoded Text : BEST OF LUCK
Text
Shift
:
Value
2:
RUIJGGEVGGBKSAGG
:
11
Example
Enter
Coded
Enter
the
Invalid Shift Value.
Text
Shift
:
Value
3:
UHINBYLKKQCHHYLKK
:
27
String words[]={"", "One", "Two", "Three", "Four", "Five", "Six","Seven", "Eight", "Nine","Ten",
"Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen",
"Twenty","Twenty one", "Twenty two", "Twenty three", "Twenty four", "Twenty five",
"Twenty six","Twenty seven","Twenty eight", "Twenty nine"};
/* The below code is for finding whether to print the word 'minute' or 'minutes' */
String plu, a;
if(m == 1)
plu = "Minute";
else
plu = "Minutes";
/* When we have minutes from 31-59, we print the hour ahead of the given hour
* like 6:55 will be 5 minutes to 7 and not 5 minutes to 6
* when we print the hour ahead of the given hour, we face a problem at hour = 12
* because if we print an hour ahead of 12, it will be thirteen, but we want 1
* so the below code checks this & decides what hour to print in words when minutes is from 31-59
*/
if(h==12)
Output:
Example
Enter
Hours
Enter
Minutes
Output : 12:39 Twenty one Minutes to One
:
:
1:
12
39
Example
Enter
Hours
Enter
Minutes
Output : 12:39 Twenty one Minutes to One
:
:
2:
12
39
Example
Enter
Hours
Enter
Minutes
Output : 7:16 Sixteen Minutes past Seven
:
:
3:
7
16
Example
Enter
Hours
Enter
Minutes
Output : 5:30 Half past Five
:
:
4:
5
30
if(n>5)
System.out.println("Enter a number between 1 to 5 ");
else
{
int i,j,k,t;
/*Initializing every cell of the matrix with 0 */
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
A[i][j] = 0;
i=0;
j = n/2;
k = 1;
while(k<=n*n)
{
A[i][j] = k++;
i--; // Making one step upward
j++; // Moving one step to the right
if(i<0 && j>n-1) // Condition for the top-right corner element
{
i = i+2;
j--;
}
if(i<0) // Wrapping around the row if it goes out of boundary
i = n-1;
if(j>n-1) // Wrapping around the column if it goes out of boundary
j = 0;
if(A[i][j]>0) // Condition when the cell is already filled
{
i = i+2;
j--;
k = 1;
for(j=0;j<n;j++)
{
A[i][j] = k++;
j = n-1;
for(i=0; i<n/2; i++)
{ /* swapping corner elements of primary diagonal */
t = A[i][i];
A[i][i] = A[j][j];
A[j][j] = t;
/* swapping corner elements of secondary diagonal */
t = A[i][j];
A[i][j] = A[j][i];
A[j][i] = t;
j--;
}
for(j=0;j<n;j++)
{ System.out.print(A[i][j]+ "\t");
}
System.out.println();
Output
Starting from the right, double every other digit (e.g., 7 becomes 14).
2.
3.
import java.io.*;
class IMEI
{
int sumDig(int n) // Function for finding and returning sum of digits of a number
{
int a = 0;
while(n>0)
{ a = a + n%10;
n = n/10;
}
return a;
}
public static void main(String args[])throws IOException
{
d = (int)(n%10);
if(i%2 == 0)
{
}
sum = sum + ob.sumDig(d); // Finding sum of the digits
n = n/10;
}
if(sum%10==0)
System.out.println("Valid IMEI Code");
else
System.out.println("Invalid IMEI Code");
} }}
Output:
1. Enter
a
Output
Valid IMEI Code
15
2. Enter
a
Output
Invalid IMEI Code
15
3. Enter
a
Output : Invalid Input
digit
:
digit
:
15
digit
IMEI
Sum
code
IMEI
Sum
code
IMEI
code
:
=
654122487458946
80
799273987135461
79
79927398713
import java.io.*;
class UniqueNumber
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter any number : ");
int n=Integer.parseInt(br.readLine());
if(flag==0)
System.out.println("**** The Number is a Unique Number ****");
else
System.out.println("**** The Number is Not a Unique Number ****");
}
}
Output:
Enter any number : 3121
**** The Number is Not a Unique Number ****
import java.io.*;
class Dec2Oct
{ public static void main(String args[])throws IOException
{ BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter a decimal number : ");
int n=Integer.parseInt(br.readLine());
int r;
String s=""; //variable for storing the result
//array storing the digits (as characters) in the octal number system
char dig[]={'0','1','2','3','4','5','6','7'};
while(n>0)
{ r=n%8; //finding remainder by dividing the number by 8
s=dig[r]+s; //adding the remainder to the result and reversing at the same time
n=n/8;
}
System.out.println("Output = "+s);
}}
Output:
Enter a decimal number : 25
Output = 31
Enter a decimal number : 465
Output = 721
class Swap_Strings
{
}
}
Output:
Enter the 1st String : Java For
Enter the 2nd String : School is Fun
Strings Before Swapping :
1st String = Java For
char ch;
System.out.println("Output:");
System.out.println("=========================="); //this is just for styling the look of the output
System.out.println("Alphabet\tFrequency");
System.out.println("==========================");
/* Counting frequency of alphabets begins below */
for(int i=0; i<26; i++)
{ for(int j=0; j<l; j++)
{ ch=s.charAt(j); //extracting characters of the string one by one
if(ch==alph[i]) //first checking the whole string for 'a', then 'b' and so on
freq[i]++; //increasing count of those aplhabets which are present in the string
}
}
for(int i=0; i<26; i++)
{
if(freq[i]!=0) //printing only those alphabets whose count is not '0'
System.out.println(" "+alph[i]+"\t\t
}
Output:
Enter any string: ilovejavaforschool
Output:
==========================
Alphabet
Frequency
==========================
a
2
c
1
e
1
f
1
h
1
i
1
j
1
"+freq[i]);
l
o
r
s
v
2
4
1
1
2
}}
Output:
1. Enter
a
Output = One Hundred And Twenty Nine
Number
2. Enter
a
Number
Output = Eight Thousand Three Hundred And Seven
129
8307
3. Enter
Out of Range
Number
54987
import java.io.*;
class Circular_Matrix
{
A[r2][i]=k++;
}
for(int j=r2-1;j>=r1+1;j--)
{
}
A[j][c1]=k++;
c1++;
c2--;
r1++;
r2--;
}
/* Printing the Circular matrix */
System.out.println("The Circular Matrix is:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+ "\t");
}
System.out.println();
}
Output:
b=1;
c=0;
limit=0;
}
int fib(int n) //Recursive function generating the 'nth' term of Fibonacci Series
{
if(n<=1)
return a;
else if(n==2)
return b;
else
return (fib(n-1)+fib(n-2));
}
void generate_fibseries() //Function generating all the Fibonacci Series numbers upto 'n' terms
{
System.out.println("The Fibonacci Series is:");
for(int i=1;i<=limit;i++)
{
c=fib(i);
System.out.print(c+" ");
}
Output:
Enter the limit : 11
The Fibonacci Series is:
0 1 1 2 3 5 8 13 21 34 55
Enter the limit : 20
The Fibonacci Series is:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
int l, y, d, m;
String dd, mm, yy;
//array storing the maximum days of every month
int maxdays[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//array storing the month names
String month[]={ "", "January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December" };
System.out.print("Enter any date in 8 digits (ddmmyyyy) format: ");
String date = br.readLine(); //inputting the date in String format
l = date.length(); //finding number of digits in the given input
if(l==8) //performing the task only when number of digits is 8
{
dd = date.substring(0,2); //extracting the day in String format
mm = date.substring(2,4); //extracting the month in String format
yy = date.substring(4); //extracting the year in String format
d = Integer.parseInt(dd); //day in Integer format
m = Integer.parseInt(mm); //month in Integer format
y = Integer.parseInt(yy); //year in Integer format
if((y%400==0) || ((y%100!=0)&&(y%4==0))) // condition for leap year
{
maxdays[2]=29;
}
/* checking whether the day, month and year are within acceptable range
i.e. there cannot be an input like 35012013 because 35/01/2013 is unacceptable*/
else
{
/* First Part */
System.out.println("Date in dd/mm/yyyy format = "+dd+"/"+mm+"/"+yy);
/* Second Part */
System.out.print("Date in dd, month name, yyyy format = "+dd+" "+month[m]+", "+yy);
else
System.out.println("Wrong Input");
}}
Output:
1) Enter any date in 8 digits (ddmmyyyy) format: 02052013
Date in dd/mm/yyyy format = 02/05/2013
Date in dd, month name, yyyy format = 02 May, 2013
2) Enter any date in 8 digits (ddmmyyyy) format: 12111963
Date in dd/mm/yyyy format = 12/11/1963
Date in dd, month name, yyyy format = 12 November, 1963
3) Enter any date in 8 digits (ddmmyyyy) format: 252013
Wrong Input
4) Enter any date in 8 digits (ddmmyyyy) format: 29022013
The day, month or year are outside acceptable limit
import java.io.*;
class Date_Difference
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//function for checking for Leap Year
int isLeap(int y)
{
if((y%400==0) || ((y%100!=0)&&(y%4==0)))
return 29;
else
return 28;
}
//function for checking date validation
boolean dateValidate(int d, int m, int y)
{
month[2]=isLeap(y);
if(m<0 || m>12 || d<0 || d>month[m] || y<0 || y>9999)
return false;
else
return true;
}
//function for finding day number from year = 1 till the inputted year
int dayno(int d, int m, int y)
{
int dn=0;
month[2]=isLeap(y);
for(int i=1;i<m;i++)
{
dn=dn+month[i];
}
dn=dn+d;
for(int i=1;i<y;i++)
{
if(isLeap(i)==29)
dn=dn+366;
else
dn=dn+365;
}
return dn;
}
public static void main(String args[])throws IOException
{
Date_Difference ob=new Date_Difference();
System.out.print("Enter the 1st date in (dd/mm/yyyy) format: ");
String date1=br.readLine().trim();
int p,q;
System.out.println("Invalid Date");
}
}
OUTPUT:
Date 1 : 20/12/2012
Date 2 : 11/02/2013
Output:Difference = 54 days
Output:
Enter a decimal number : 25
Output = 11001
Enter a decimal number : 47
Output = 101111
class Dec2Hex
{ public static void main(String args[])throws IOException
{ BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter a decimal number : ");
int n=Integer.parseInt(br.readLine());
int r;
String s=""; //variable for storing the result
//array storing the digits (as characters) in a hexadecimal number system
char dig[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(n>0)
{
r=n%16; //finding remainder by dividing the number by 16
s=dig[r]+s; //adding the remainder to the result
n=n/16;
}
System.out.println("Output = "+s);
}}
Output:
Enter a decimal number : 47
Output = 2F
import java.io.*;
import java.util.*;
class Sent_Merge_Rev
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of sentences: "); //inputting the number of sentences to accept
int n = Integer.parseInt(br.readLine());
String s = "";
//converting the sentence into StringTokenizer giving the given punctuation marks
System.out.println("Output: "+rev);
}
}
Output:
Example
1:
Enter
the
number
of
sentences:
2
Enter Sentence 1: Emotions, controlled and directed to work, is character.
Enter
Sentence
2:
By
Swami
Vivekananda.
Output: Vivekananda Swami By character is work to directed and controlled Emotions
Example
2:
Enter
the
number
of
sentences:
3
Enter
Sentence
1:
Did
you
know?
Enter
Sentence
2:
ICSE
and
ISC
computer
is
really
easy.
Enter
Sentence
3:
Thanks
to
javaforschool!
Output: javaforschool to Thanks easy really is computer ISC and ICSE know you Did
import java.io.*;
class SymetricMatrix_ISC2014
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int m=Integer.parseInt(br.readLine());
int A[][]=new int[m][m];
if(m>2 && m<10) // Checking for valid input of rows and columns size
{
{
if(A[i][j] != A[j][i])
{ flag = 1; // Setting flag = 1 when elements do not match
break;
}
if(flag == 1)
System.out.println("nThe given Matrix is Not Symmetric");
else
System.out.println("nThe given Matrix is Symmetric");
/* Finding sum of the diagonals */
int ld = 0, rd = 0;
for(int i=0;i<m;i++)
{ for(int j=0;j<m;j++)
{ if(i == j) // Condition for the left diagonal
{
ld = ld + A[i][j];
}
if((i+j) == (m-1)) // Condition for the right diagonal
{
rd = rd + A[i][j];
}
}
else
System.out.println("The Matrix Size is Out Of Range");
}}
Output:
Program 30:Inheritance
A super class Record has been defined to store the names and ranks of 5 students. Define a sub
class Rank to find the highest rank along with the name. The details of both classes are given below:
Class name : Record
Data Members / instance variables:
name[ ] : to store the names of students
rnk[ ] : to store the ranks of students
Member functions:
Record() : constructor to initialize data members
void readvalues() : to store names and ranks
void display() : displays the names and the corresponding ranks
Class name : Rank
Data Members / instance variables:
index : integer to store the index of the topmost rank
Member functions
Rank() : constructor to invoke the base class constructor and to initialize index to 0.
void highest() : finds the index location of the topmost rank and stores it in index without sorting the
array 6
void display() : displays the name and ranks along with the name having the topmost rank.
Specify the class Record giving details of the constructor(), void readvalues(), void display().
Using the concept of inheritance, specify the class Rank giving details of constructor(), void
highest() and void display().
import java.io.*;
class Record //superclass
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name[];
int rnk[];
Record()
{
name = new String[5];
rnk = new int[5];
}
void readvalues()throws IOException
{
System.out.println("*** Inputting The Names And Ranks ***");
for(int i=0;i<50;i++)
{
System.out.print("Enter name of student "+(i+1)+" : ");
name[i]=br.readLine();
System.out.print("Enter his rank : ");
rnk[i]=Integer.parseInt(br.readLine());
}
void display()
{
System.out.println("NamettRank");
System.out.println("-------tt-------"); //this is just for styling the output. You can skip it !
for(int i=0;i<50;i++)
{
System.out.println(name[i]+"tt"+rnk[i]);
}
Rank()
{
super(); //invoking the constructor of superclass
index = 0;
}
void highest()
{
int min = rnk[0];
for(int i=0;i<50;i++)
{
if(rnk[i]<min)
{
index = i;
}
void display()
{
super.display(); //calling the superclass function display()
System.out.println("nTop most rank = "+rnk[index]);
System.out.println("Student with topmost rank = "+name[index]);
}
} //end of subclass Rank
/* In your exams you don't need to write the below given code
We are writing it so as to familiarize the students on how to run programs
based on the concept of inheritance.*/
public class Question11_ISC2011 //Class which will contain the main() method and execute the program
{
Output:
*** Inputting The Names And Ranks ***
Enter name of student 1 : Aamir
Enter his rank : 5
Enter name of student 2 : Zakir
Enter his rank : 2
Enter name of student 3 : Saalim
Enter his rank : 7
Enter name of student 4 : Samir
Enter his rank : 3
Enter name of student 5 : Saif
Enter his rank : 6
*** Output ***
Name
Rank
Aamir
5
Zakir
2
Saalim
7
Samir
3
Saif
6
Top most rank = 2
Student with topmost rank = Zakir