Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 115

SESSION: 2022-23

ISC COMPUTER
SCIENCE PROJECT

INTERNAL EXAMINER EXTERNAL EXAMINER

SUBMITTED BY:-

ANSH MISHRA
XII-A
ACKNOWLEDGEMENT
This is to inform that I Ansh Mishra of class XII th A has completed
my computer project . Project work is the best way of learning by doing . I
learned a lot by doing this project .This project contains 30 programs and
each program contains an algorithm , Program code , Variable description
table and an output screen .

I would like to thank my Teacher Mr . Saurabh Chauhan under who se


guidance I have successfully completed this project . I am indebted for his
expert advice , motivation and suggestion provided during preparation of
this project .

At last I would like to thank my family member s and my friends who


helped me in completing my project .

_________________ ________________
Teacher ’s Signature Student ’s Signature

_________________ _________________
Examiner ’s Signature Principal ’s Signature
Index:

Serial TOPIC PAGE No. Remarks Teacher’s


No. Signature
1. Strings.
● Program 1
● Program 2
● Program 3
● Program4
● Program 5
● Program6
2. Number
Related
programs.
● Program 1
● Program 2
● Program 3
● Program4
● Program 5

3. Arrays.
● Program 1
● Program 2
● Program 3
● Program4

4. Recursion.
● Program 1
● Program 2
● Program 3
● Program4
5. Inheritance
● Program 1
● Program 2
● Program 3

6. Data
Structure.
● Program 1
● Program 2
● Program 3

7. Date and
Time
related
programs.
● Program 1
● Program 2

8. Object
Passing.
● Program 1
● Program 2
● Program 3

9. Bibliography
ARRAYS:-

Program 1:
Write a program to declare a square matrix M [ ] [ ] of order ‘N’ where ‘N’ must
be greater than 3 and less than 10. Allow the user to accept three different
characters from the keyboard and fill the array according to the instruction
given below: (i) Fill the four corners of the square matrix by character 1. (ii) Fill
the boundary elements of the matrix (except the four corners) by character 2.
(iii) Fill the non-boundary elements of the matrix by character 3. Test your
program with the following data and some random data: Example 1:

INPUT:
N=4
FIRST CHARACTER: @
SECOND CHARACTER: ?
THIRD CHARACTER: #
OUTPUT:
@??@
?##?
?##?
@??@

ALGORITHM:
STEP 1: START.
STEP 2: ASK FOR USER INPUT.
STEP 3: CHECK FOR THE CORNER ELEMENTS IN THE FIRST IF
STATEMENT AND FILL THE 1st CHARACTER.
STEP 4: CHECK FOR THE NON-BOUNDARY ELEMENTS AND
FILL THE 3rd CHARACTER.
STEP 5: FILL THE 2nd CHARACTER IN THE ELSE PART.
STEP 6: PRINT THE ARRAY IN MATRIX FORM.
STEP 7: END.

import java.util.*; //importing


public class DDArray
{ //class opened
public static void main(String args[])
{
int N;
char ar[][],a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter array length");
N=sc.nextInt();
ar=new char[N][N];
System.out.println("Enter 3 Characters");
a=sc.next().charAt(0);
b=sc.next().charAt(0);
c=sc.next().charAt(0);
if(N>3 && N<10)
{
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
if(((i==0)||(i==N-1)) &&
((j==0)||(j==N-1))) // checks for
the 1st character
ar[i][j]=a;
else if
((i!=0)&&(j!=0)&&(i!=N-1)&&(j!=N-1)) //checks for the 3rd
character
ar[i][j]=c;
else
ar[i][j]=b;
}
}
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
System.out.print(ar[i][j]+" ");
System.out.println();
}
}
else
System.out.println("INVALID LENGTH");
}
} //class closed

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NO NAME
1. ar char array
2. a char Stores 3rd characters
3. b char Stores 2nd character
4. c char Stores 1st character
5. N int Stores array order
6. i int Looping variable
7. f int Looping variable
Program 2:
Write a program to declare a matrix A [ ] [ ] of order (M x N) where ‘M’ is the
number of rows and ‘N’ is the number of columns such that the value of ‘M’
must be greater than 0 and less than 10 and the value of ‘N’ must be greater
than 2 and less than 6. Allow the user to input digits (0 - 7) only at each
location, such that each row represents an octal number. Example: 2 3 1
(decimal equivalent of 1st row = 153 i.e., 2x82 + 3x81 + 1x80 ) 4 0 5
(decimal equivalent of 2nd row = 261 i.e., 4x82 + 0x81 + 5x80 ) 1 5 6
(decimal equivalent of 3rd row = 110 i.e., 1x82 + 5x81 + 6x80 ) Perform the
following tasks on the matrix: (a) Display the original matrix.
(b) Calculate the decimal equivalent for each row and display as per the
format given below. Example 1
INPUT:
M=1
N=3
ENTER ELEMENTS FOR ROW 1: 1 4
4 OUTPUT:
FILLED MATRIX DECIMAL EQUIVALENT
144 100
Example 2
INPUT:
M=3
N=4

OUTPUT:
FILLED MATRIX DECIMAL EQUIVALENT
1137 607
2106 1094
0245 165
import java.util.*;
public class DArray
{ //class opened
public static void main(String args[])
{ //main opened
int ar[][],M,N,j=0,n=0,k;
double s=0d;
Scanner sc =new Scanner(System.in);
System.out.println("Enter Number of Rows");
M=sc.nextInt();
System.out.println("Enter Number of
Columns");
N=sc.nextInt();
ar=new int[M][N];
k=N-1;
while(j<M)
{
System.out.print("Enter elements
of"+(j+1)+"th row (0-7 only): ");
for(int i=0;i<N;i++)
{
ar[j][i]=sc.nextInt();
}
j++;
}
while(n<M)
{
s=0;
k=N-1;
for(int i=0;i<N;i++) //calculates the
decimal equivalent
{
s=s+(ar[n][i]*Math.pow(8,k));
k--;
}
System.out.println("Decimal Equivalent
"+n+"th row: "+s);
n++;
}
} //main closed
} //class closed
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. ar int Array to store integers as per user
inputs
2. M int Stores number of rows of the array
3. N int Stores number of columns of the
array
4. k int Stores the power of 8 according to
the number of columns
5. s double Stores the decimal equivalent of the
given row
Program 3:
Write a program to transpose a matrix. Perform the following tasks:-
(i) Take input in a double dimensional array. (ii)Rotate the array by 90
degrees clockwise.
(iii) Print the updated array in matrix form. Example:
INPUT: 1 2 3
456
789
OUTPUT:
741
852
963
import java.util.*;
public class DDArray90
{
public static void main(String args[])
{
int n=3;
int arr[][]=new int [n][n]; int
arr1[][]=new int [n][n]; Scanner
sc=new Scanner(System.in);
System.out.println("Enter array elements");
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
arr[i][j]=sc.nextInt();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
System.out.print(arr[i][j]+" ");
System.out.println();
}
for(int j=0;j<n;j++)
{
for(int i=0;i<n;i++)
{
arr1[i][n-1-j]=arr[j][i];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
System.out.print(arr1[i][j]+" ");
System.out.println();
}
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. n int Used to store
order of matrix.
2. arr int Used to take the
original array as
user input.
3. arr1 int Stores the
updated array.
4. i int Looping variable.
5. j int Looping variable.
Program 4:
Write a program to declare a matrix A[][] of order (M*N) such that the
value of both M & N must be greater than 2 and less than 8. Allow
the user to input integers into the matrix and perform the following
task:
a) sort the matrix elements in descending order
b) calculate sum of boundary elements before and after sorting
c) display the original matrix and sorted matrix and sum also.

ALGORITHM:
STEP 1: START.
STEP 2: TAKE INPUT IN THE ARRAY..
STEP 3: TRANSFER ARRAY ELEMENTS INTO A
SINGLE DIMENSIONAL ARRAY..
STEP 4: SORT THE SINGLE DIMENSIONAL ARRAY USING
BUBBLE SORT TECHNIQUE..
STEP 5: TRANSFER THE SORTED ARRAY TO THE
DOUBLE DIMENSIONAL ARRAY .
STEP 6: DISPLAY BOTH ORIGINAL AND ARRANGED ARRAY.
STEP 7: END.

import java.util.*;
public class DDSort
{
public static void main(String args[])
{
int A[][],M,N,arr[],k=0,sum=0; Scanner
sc=new Scanner(System.in);
System.out.println("Enter number of rows
and number of columns respectively");
M=sc.nextInt();
N=sc.nextInt();
A=new int[M][N];
arr=new int[M*N];
if(M>2 && M<8 && N<8 && N>2)
{
System.out.println("Enter array
elements");
for(int i=0;i<M;i++)
{
for(int j=0;j<N;j++)
{
A[i][j]=sc.nextInt();
if(k<(M*N))
{
arr[k]=A[i][j];
k++;
}
}
}
for(int i=0;i<(M*N);i++)
{
for(int j=0;j<(M*N)-i-1;j++)
{
if(arr[j]<arr[j+1])
{
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(int i=0;i<M;i++)
{
for(int j=0;j<N;j++)
{
if(((i==0)||(i==M-1)) ||
((j==0)||(j==N-1)))
{
sum=sum+A[i][j];
}
}
}
System.out.println("ORIGINAL ARRAY");
for(int i=0;i<M;i++) {

for(int j=0;j<N;j++)
System.out.print(A[i][j]+" ");
System.out.println();
}
k=0;
for(int i=0;i<M;i++)
{
for(int j=0;j<N;j++)
{
A[i][j]=arr[k++];
}
}
System.out.println("SORTED ARRAY");
for(int i=0;i<M;i++) {

for(int j=0;j<N;j++)
System.out.print(A[i][j]+" ");

System.out.println();
}
System.out.println("Sum of Boundary
Elements: "+sum);
}
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. A int Array to store
integers.
2. M int Stores number
of rows.
3. N int Stores number
of columns.
4. arr int Single
dimensional
array used for
sorting.
5. i int Looping
variable.
6. j int Looping
variable.
7. k int Counter
variable.
NUMber related program:

Program 1:
An Evil number is a positive whole number which has an even number of
1’s in its binary equivalent. Example: Binary equivalent of 9 is 1001, which
contains an even number of 1’s. Thus, 9 is an Evil Number. A few Evil
numbers are 3, 5, 6, 9..... Design a program to accept a positive whole
number ‘N’ where N>2 and N<100. Find the binary equivalent of the
number and count the number of 1s in it and display whether it is an
Evil number or not with an appropriate message.

ALGORITHM:
STEP 1: START.
STEP 2: ASK FOR USER INPUT.
STEP 3: CALCULATE THE BINARY EQUIVALENT OF THE NUMBER.
STEP 4: COUNT THE NUMBER OF 1s IN THE BINARY EQUIVALENT.
STEP 5: IF THERE ARE EVEN NUMBER OF 1s, EVIL NUMBER.
STEP 6: ELSE NOT AN EVIL NUMBER..
STEP 7: END.

import java.util.*;
public class evil
{
int b=0;
int binary(int n) //finds the binary
equivalent of the number
{
if(n>0)
{
int d=n%2;
binary(n/2);
b=b*10+d;
}
return b;
}
public static void main(String args[])
{
int N,c,d=0,a=0;
Scanner sc=new Scanner(System.in);
evil ev=new evil();
System.out.println("Enter a number");
N=sc.nextInt();
c=ev.binary(N);
while(c>0) //counts the number of 1s in the
number
{
a=c%10;
if(a==1)
d++;
c=c/10;
}
if(d%2==0)
System.out.println("Evil Number");
else
System.out.println("Not an Evil Number");
}
}
VARIABLE DESCRIPTION TABLE
SERI VARIAB DATATYP DESCRIPTION
AL LE E
NO. NAME
1. N int Stores the number
2. c int Stores the binary equivalent of the number
3. a int Extracts digits from the number
4. d int Stores number of 1s present in the number
Program 2:
A Prime-Adam integer is a positive integer (without leading zeros) which is a
prime as well as an Adam number. Prime number: A number which has only
two factors, i.e., 1 and the number itself. Example: 2, 3, 5, 7 … etc. Adam
number: The square of a number and the square of its reverse are
reverse to each other. Example: If n=13 and reverse of ‘n’= 31, then, (13)2
= 169 (31)2 = 961 which is the reverse of 169. Thus 13, is an Adam
number. Accept two positive integers m and n, where m is less than n as
user input. Display all Prime-Adam integers that are in the range between
m and n (both inclusive) and output them along with the frequency, in the
format given below: Test your program with the following data and some
random data:
Example
INPUT:
m=5n
= 100
OUTPUT:
THE PRIME-ADAM INTEGERS
ARE: 11, 13, 31
FREQUENCY OF PRIME-ADAM INTEGERS IS:
3 import java.util.*;
public class PrimeAdam
{
int prime(int n) //checks if the number is
prime
{
int i,f=0;
for(i=2;i<n;i++)
{
if(n%i==0)
{
f++;
break;
}
}
return f;
}
int reverse(int p) //returns the reverse of
the number
{
int rev=0,r;
while(p>0)
{
r=p%10;
rev=rev*10+r;
p=p/10;
}
return rev;
}
int adam(int n) //checks if the number is
PRIME-ADAM
{
if(prime(n)==0 &&
n*n==reverse(reverse(n)*reverse(n)))
return 1;
else
return 0;
}
public static void main(String args[])
{
int m,n,c=0;
Scanner sc=new Scanner(System.in);

PrimeAdam pa=new PrimeAdam();


System.out.println("Enter Starting
number");
m=sc.nextInt();
System.out.println("Enter Ending number");
n=sc.nextInt();
System.out.println("Prime Adam Numbers
are:-");
for(int i=m;i<=n;i++) //prints all the
PRIME-ADAM integers between the given range
{
if(pa.adam(i)==1)
{
System.out.print(i+" ");
c++;
}
}
System.out.println();
System.out.println("Frequency of Prime Adam
numbers: "+c);
}
}
VARIABLE DESCRIPTION TABLE
SERIA VARIABL DATATYP DESCRIPTION
L NO. E NAME E
1. n int Formal parameter of prime(...)method
2. i int Looping variable
3. f int Counts and stores number of factors
4. p int Formal parameter of reverse(...)method
5. rev int Stores reverse of a number
6. r int Extracts and stores digits of the number
one by one
7. m int Lower limit of range entered by user
8. n int Upper limit of the range entered by user
9. c int Counts the frequency of PRIME-ADAM
number in the given range
Program 3:
A Circular Prime is a prime number that remains prime under cyclic shifts
of its digits. When the leftmost digit is removed and replaced at the end of
the remaining string of digits, the generated number is still prime. The
process is repeated until the original number is reached again.A number
is said to be prime if it has only two factors 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.Accept a positive number N and check
whether it is a circular prime or not. The new numbers formed after
the shifting of the digits should also be displayed.
Test your program with the following data and some random data:
Example 1
INPUT:
N=197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME.

import java.util.*;
public class CircularPrime
{
boolean prime(int n)
{ //checks for prime number
int f=1;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
f=0;
}
}
if(f==1)
return true;
else
return false;
}
String circle(String s)
{
return(s.substring(1)+s.charAt(0));
}
public static void main(String args[])
{
int a,c=0;
Scanner sc=new Scanner(System.in);
CircularPrime cp=new CircularPrime();
System.out.println("Enter a number");
a=sc.nextInt();
int m=a;
while(cp.prime(a)==true)
{
String as=Integer.toString(a);
String d=cp.circle(as);
a=Integer.parseInt(d); c++;
}
String b=Integer.toString(m);
if(c==b.length())
System.out.println("CIRCULAR PRIME");
else
System.out.println("NOT A CIRCULAR PRIME");
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. f int Flag variable.
2. a int Stores the
number given by
the user.
3. c int Counter
variable.
4. m int Stores the copy
of the number
5. as String Stores the
number in string.
6. d String Stores the
number after its
rearrangement.
7. b String Stores the
number in string.
Program 4:

A Fascinating number is one which when multiplied by 2 and 3 and then,


after the results are concatenated with the original number, the new
number contains all the digits from 1 to 9 exactly once. There can be
any number of zeroes and are to be ignored. Example:

273
273*1 = 273
273*2 = 546
273*3 = 819
Concatenating result: 273546819, which contains all the digits from 1 to
9 exactly once.
Accept two positive integers m and n, where m must be less than n and
the values of both ‘m’ and ‘n’ must be greater than 99 & less than 10000
as user input. Display all the Fascinating numbers that are in range
between m and n (both inclusive) and output them along with frequency, in
the format given below:-
INPUT: m = 100
n = 500
OUTPUT: The fascinating number
are 192 219 273 327
Frequency: 4
import java.util.*;
public class Fascinating
{
int fascinate(int n)
{
int a=n*2;
int b=n*3;
int k=0;
String d="123456789";
String a1=Integer.toString(a);
String b1=Integer.toString(b);
String c1=Integer.toString(n);
String f=c1+ a1+ b1;
for(int i=0;i<d.length();i++)
{
char ch=d.charAt(i);
if(f.indexOf(ch)==-1 ||
f.indexOf(ch)!=f.indexOf(ch))
{
k=1;
break;
}
}
return k;
}
public static void main(String args[])
{
int m,n,v=0;
Scanner sc=new Scanner(System.in);
Fascinating fs=new Fascinating();
System.out.println("Enter lower limit");
m=sc.nextInt();
System.out.println("Enter upper limit");
n=sc.nextInt();
if(m<n && m>99 && m<1000 && n>99 &&
n<10000)
{
System.out.println("The Fascinating
numbers are:-");
for(int i=m;i<=n;i++)
{
if(fs.fascinate(i)==0)
{
System.out.print(i+" ");
v++;
}
}
System.out.println("FREQUENCY: "+v);
}
else
System.out.println("INVALID RANGE");

}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NUMBER
1. a int To store the
product of
number with 2.
2. b int To store the
product of the
number with 3.
3. k int Flag variable.
4. f String Stores the
concatenated
result.
5. m int Stores lower
boundary.
6. n int Stores upper
boundary.
7. v int Stored frequency.
Program 5:

Write a program in Java to check whether the given number is a spy


number or not. A number whose sum of digits is equal to the product of
its digits is called a spy number. For example, 1124.

ALGORITHM:
STEP 1: START.
STEP 2: ASK THE USER TO ENTER A NUMBER.
STEP 3: EXTRACT THE DIGITS OF THE NUMBER ONE BY ONE.
STEP 4: CALCULATE THE SUM OF DIGITS.
STEP 5: CALCULATE THE PRODUCT OF DIGITS.
STEP 6: COMPARE THE SOME OF DIGITS WITH PRODUCT
OF DIGITS.
STEP 7: IF EQUAL, IT IS A SPY NUMBER.
STEP 8: ELSE IT IS NOT A SPY NUMBER.
STEP 9: END.

import java.util.Scanner;
public class Spy_Number
{
public static void main(String[] args)
{ Scanner sc= new Scanner(System.in);
int digit, num;
System.out.println("Enter a number");
num = sc.nextInt();
int product = 1;
int sum = 0;
//Extract digit, add to sum and multiply to
product
while(num>0){
digit = num%10;
sum += digit;
product *= digit;
num=num/10;
}
if(sum == product)
System.out.println("Spy Number");
else
System.out.println("Not a Spy Number");
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. num int Stores the
number entered
by the user.
2. digit int Extracts and
stores digits.
3. sum int Stores the sum
og digits.
4. product int Stores the
product of digits.
strings:-

Program 1:
The potential of a word is found by adding the ASCII value of the
alphabets. (ASCII values of A to Z are 65 to 90). Write a program to
accept a sentence which may be terminated by either “.”, “?” or “!” only.
The words of the sentence are separated by a single blank space and
are in the UPPER CASE. Decode the words according to their potential
and arrange them in ascending order of their potential strength .

import java.util.*;
public class Potential
{
int position(String w) //returns the
potential of the word
{
int p=0;
for(int i=0;i<w.length();i++)
{
p=p+(int)w.charAt(i);
}
return p;
}

public static void main(String args[])


{
Scanner sc=new Scanner(System.in);
Potential pt=new Potential();
int num[],n,j=0;
String arr[],b;
System.out.println("Enter the sentence");

String s=sc.nextLine();
StringTokenizer st=new
StringTokenizer(s,".,!,?");
n=st.countTokens();
num=new int[n];
arr=new String[n];
while(st.hasMoreTokens())
{
b=st.nextToken();
arr[j]=b;
num[j]=pt.position(b);
j++;
}
for(int k=0;k<n-1;k++) //number of passes
to sort the array in ascending order of their
potentials
{
for(int i=0;i<n-k-1;i++)
{
if(num[i]>num[i+1])
{
int temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
String tempo=arr[i];
arr[i]=arr[i+1];
arr[i+1]=tempo;
}
}
}
System.out.println("Sorted sentence");
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. num int Array to store the potential of words
of the sentence
2. n int Stores the number of words in the
string
3. arr String Array to store the words of the
sentence
4. b int Stores the words of the sentence one
by one
5. s int Stores the sentence entered by the
user
Program 2:
Write a program to check for the validity of the code input by the user.
The code should only consist of the letters A,C,E,G,I,K . Only these
characters in uppercase are permitted and the length of the code should
not be more than 6 , secondly the repetition of the characters is not
allowed . Check for the code taking account of the above factors .
import java.util.*; public
class ValidityCheck
{
public static void main(String args[])
{
int f=0;
String s,v="ACEGIK";
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE STRING");
s=sc.nextLine();
if(s.length()!=6) //checks for the correct
length
{
System.out.println("INVALID");
System.exit(0); //terminates the program
}
else
{
for(int i=0;i<6;i++) //checks for the
given characters
{
char p=s.charAt(i);
if(v.indexOf(p)==-1)
f=1;

}
if(f==0)
System.out.println("VALID");
else
System.out.println("INVALID");
}
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. f int Checks for the presence of all the
valid characters
2. s String Stores the string entered by the user
3. v String Stores the set of all valid characters
4. p String Extracts all the characters from the
string one by one

Program 3:
Write a program to accept a sentence which may be terminated by
either’.’ ,’?’or ‘!’only. The words are to be separated by a single blank space in
uppercase. Check for the validity of the sentence and convert the non-
palindrome words by concatenating the words by its reverse( excluding
the last character ).Display the original sentence along with the converted
sentence .
INPUT : THE BIRD IS FLYING.
OUTPUT : THEHT BIRDRIB ISI FLYINGNIYLF
import java.util.*; // importing scanner
class
public class PalindromeSentence
{ //class opened
String revStr(String s) //returns the reverse
of the word
{
String p="";
for(int i=0;i<s.length()-1;i++)
{
p=s.charAt(i)+p;
}
return p;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
PalindromeSentence Ps=new
PalindromeSentence();
String s,w,p="";
System.out.println("Enter the sentence");
s=sc.nextLine();
s=s.toUpperCase();
StringTokenizer st= new StringTokenizer(s);

while(st.hasMoreTokens())
{
w=st.nextToken();
if(w.equals(Ps.revStr(w))
p=p+w+“ ”;
else
p=p+w+Ps.revStr(w)+" ";
}
p=p.trim();
System.out.println("ORIGINAL STRING:"+s);
System.out.println("UPDATED STRING:"+p);
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. p String Stores the updated string
2. s String Stores the sentence
3. w String Stores each word of the sentence one
by one

Program 4:
A class Rearrange has been defined to modify a word by bringing all the
vowels in the word at the beginning followed by the consonants. [10]
Example:
ORIGINAL becomes OIIARGNL
Some of the members of the class are given below:
Class name: Rearrange
Data Member/instance variable:
wrd: to store a word
newwrd: to store the rearranged
word Member functions/methods:
Rearrange(): default constructor
void readword(): to accept the word in UPPER case
vow freq_vow_con(): finds the frequency of vowels and consonants in
the word and displays them with an appropriate message
void arrange(): rearranges the word by bringing the vowels at
the beginning followed by consonants
void display(): displays the original word along with the rearranged word
Specify the class Rearrange, giving the details of the constructor(), void
readword(), void freq _vow_con(), void arrange() and void display().
Define the main() function to create an object and call the functions
accordingly to enable the task.import java.util.*;
public class Rearrange
{
String wrd,newwrd;
Rearrange()
{
wrd="";
newwrd="";
}
void readword()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the word");
wrd=sc.nextLine().toUpperCase();
}
void freq_vow_con()
{
String v3="AEIOU";
int c=0,v=0;
for(int i=0;i<wrd.length();i++)
{
char ch=wrd.charAt(i);
if(v3.indexOf(ch)!=-1)
v++;
else
c++;
}
System.out.println("Number of vowels: "+v);
System.out.println("Number of consonants:
"+c);
}
void arrange()
{
String v2="AEIOU";
for(int i=0;i<wrd.length();i++)
{
char ch=wrd.charAt(i);
if(v2.indexOf(ch)!=-1)
newwrd=newwrd+ch;
}
for(int i=0;i<wrd.length();i++)
{
char ch=wrd.charAt(i);
if(v2.indexOf(ch)==-1)
newwrd=newwrd+ch;
}
}
void display()
{
System.out.println("ORIGINAL WORD: "+wrd);
System.out.println("REARRANGED WORD:
"+newwrd);
}
public static void main(String args[])
{
Vonsonants vc=new Rearrange();
vc.readword();
vc.freq_vow_con();
vc.arrange();
vc.display();
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. wrd String Stores the word
entered by the
user.
2. newwrd String Stores the
rearranged word.
3. v3 String A string
containing
vowels.
4. v int Stores number of
vowels.
5. c int Stores number of
consonants.
6. v2 String A string
containing
vowels.

Program 5:
A class Encrypt has been defined to replace only the vowels in a word
by the next
corresponding vowel and forms a new word. i.e. A → E, E → I, I → O,
O → U and U → A
Example: Input: COMPUTER
Output: CUMPATIR
Some of the members of the class are given below:
Class name : Encrypt
Data members/instance variables:
wrd : to store a word
len : integer to store the length of the word
newwrd : to store the encrypted word
Methods / Member functions:
Encrypt( ) : default constructor to initialize data
members with legal initial values
void acceptword( ) : to accept a word in UPPER CASE
void freqvowcon( ) : finds the frequency of the vowels
and consonants in the word stored in ‘wrd’ and displays
them with an appropriate message
void nextVowel( ) : replaces only the vowels from the word
stored in ‘wrd’ by the next corresponding vowel and
assigns it to ‘newwrd’, with the
remaining alphabets unchanged
void disp( ) : Displays the original word along with
the encrypted word
Specify the class Encrypt giving details of the constructor( ),
void acceptword( ),
void freqvowcon( ), void nextVowel( ) and void disp( ). Define a main( )
function to create an object and call the functions accordingly to
enable the task.
import java.util.*;
public class Encrypt
{
String wrd,newwrd;
int len;
Encrypt()
{
wrd="";
len=0;
newwrd="";
}
void acceptword()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the word");
wrd=sc.nextLine().toUpperCase();
len=wrd.length();
}
void freqvowcon()
{
String v="AEIOU";
int a=0,b=0;
for(int i=0;i<len;i++)
{
char ch=wrd.charAt(i);
if(v.indexOf(ch)!=-1)
a++;
else
b++;
}
System.out.println("Number of vowels: "+a);
System.out.println("Number of consonants:
"+b);
}
void nextVowel()
{
int i=0;
String v="AEIOUAEIOU";
while(i<wrd.length())
{
char ch=wrd.charAt(i);
if(v.indexOf(ch)!=-1)
{
int d=v.indexOf(ch);
newwrd=newwrd+v.charAt(d+1);
}
else
newwrd=newwrd+ch;i++;
}
}
void display()
{
System.out.println("ORIGINAL WORD: "+wrd);
System.out.println("ENCRYPTED WORD:
"+newwrd);
}
public static void main(String args[])
{
Encrypt ep=new Encrypt();
ep.acceptword();
ep.freqvowcon();
ep.nextVowel();
ep.display();
}

}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. wrd String To store word
entered by the
user.
2. len int Stores length of
the word.
3. newwrd String Stores the
updated word.
4. a int Stores number
of vowels.
5. b int Stores number
of consonants.
6. v String A spring of
vowels.
Program 6:
Write a program in java to reverse a sentence
without reversing its individual words.You can assume that there is only
single space between the words.
Example:
INPUT: I LOVE MY DOG TEDDY
OUTPUT: TEDDY DOG MY LOVE I
import java.util.*;
public class RevLoop
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
//Input sentence
System.out.print("Enter a sentence: ");
String str = in.nextLine();
//Append whitespace for the extraction of last
word str += " ";
String reversed = "";
//repeat until no word is left
while(str.indexOf(" ") != -1)
{ //Extract word
int idx = str.indexOf(" ");
String word = str.substring(0, idx);
//Concatenate in reverse order
reversed = word + " "+ reversed;
//Remove word from the sentence
str = str.substring(idx+1);
} //Output the reverse
System.out.print("Reverse: ");

System.out.println(reversed);
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. str String Stores the
sentence
entered by the
user.
2. reversed String Stores the
reversed
sentence.
3. idx int Stores index of
a single space.
inheritance:-

Program 1:
A super class VEHICLE stores the details of a Vehicle. Another class
car is derived from VEHICLE which performs certain operations. class
name: VEHICLE
Data members/Instance Variables
String regnum: to store the registration number
char permit: the national permit category [either N, S or
L] Member Functions
VEHICLE(….) parameterized constructor to initialize data members
void Print( ) to display data members
class name: CAR
Data member/ Instance Variable
long price: to store the price of the car
double Exc: to store the excise duty to be levied on the
car Member Functions
CAR(….): parameterized constructor to initialize data members of both the
classes
void calEx( ): calculates the excise duty as per the following chart:
Permit Excise Amount
N 22% of the price
S 11% of the price
L 5% of the price
void Print( ) to display all the details of both the classes with
proper message
class VEHICLE
{
String regnum;
char permit;
VEHICLE(String r, char p) //parameterized

constructor
{
regnum=r;
permit=p;
}
void Print() //displays the member methods
of the class
{
System.out.println("Registration
Number:"+regnum);
System.out.println("Permit:"+permit);
}
}

class CAR extends VEHICLE


{
long price;
double Exc;
CAR(String r, char p, long pr)
{
super(r,p);
price=pr;
Exc=0.0d;
}
void calEx() //calculates the Excise Duty
{
permit=Character.toUpperCase(permit);
if(permit=='N')
Exc=(price*22.0)/100;
else if(permit=='S')
Exc=(price*11.0)/100;
else if(permit=='L')
Exc=(price*5.0)/100;
else
System.out.println("Invalid Permit");
}

void Print() //displays the member methods


of both the classes
{
super.Print();
System.out.println("Price:"+price);
System.out.println("Excise Duty :"+Exc);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL NO. VARIABLE DATATYPE DESCRIPTION
NAME
1. regnum String Stores
registration
number of the
car
2. premit char Stores permit
3. Exc double Stores the
calculated
Excise Duty
Program 2 :
A class Employee contains employee details and another class Salary
calculates the employee’s net salary. The details of the two classes
are given below:
Class name Employee
Data members/Instance variables
empNo String, to store the employee number
empName String, to store the employee’s name
empDesig String, to store employee’s designation
Member Functions
Employee(…..) parameterized constructor to assign values to the data
members
void display( ) displays the employee
details Class name Salary
Data members/Instance variables
basic double variable to store the basic pay
Member Functions
Salary(…) parameterized constructor to assign values to data
members of both the classes
void calculate( ) calculates the net salary as per following rules:
DA = 10% of basic
HRA = 20% of basic
salary = basic + DA + HRA
PF = 8% of salary
Net salary = salary – PF
void display( ) to display the data members of both the classes
class Employee
{
String empNo, empName, empDesig;
Employee(String no, String name, String
desig) //parameterized constructor
{
empNo=no;
empName=name;
empDesig=desig;
}
void display() //displays the member methods

of the class

{
System.out.println("Employee
number:"+empNo);
System.out.println("Employee

name:"+empName);

System.out.println("Designation:"+empDesig);
}
}

class Salary extends Employee


{
double basic;
Salary(String no, String name, String d, double
b)
{
super(no,name,d);
basic=b;
}
double DA,HRA,Salary,PF,Net;
void calculate() //calculates the Net Salary
of the Employee
{
DA=(basic*10.0)/100.0;
HRA=(basic*20.0)/100.0;
Salary=basic+DA+HRA;
PF=(Salary*8.0)/100.0;
Net=Salary-PF;
}
void display() //displays the member methods

of both the classes

{
super.display();
System.out.println("Basic Pay:"+basic);
System.out.println("DA:"+DA);
System.out.println("HRA:"+HRA);
System.out.println("Salary:"+Salary);
System.out.println("PF:"+PF);
System.out.println("Net Salary:"+Net);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE NAME DATATYPE DESCRIPTIO
NO. N
1. empNo String to store the
employee
number

2. empName String to store the


employee’s
name

3. empDesig String to store


employee’s
designation

4. basic double to store the


basic pay
5. salary double Stores salary
of the
employee
6. Net double Calculates and
stores the net
salary
Program 3:
An interface Solid is defined with a method volume( ) which returns the
volume of the implementing object. Create the classes Cylinder and
Cuboid which implement the interface Solid. These classes have
attributes which reflect their dimensions (radius, height of a cylinder,
length, breadth and height of a cuboid) which are set by their
constructors. The details of the members of the interface and both the
classes are given below:
Interface name Solid
Member functions/methods:
double volume() returns the area of the implementing solid
Class name Cylinder
Data members/instance variables:
radius to store radius of the Cylinder in decimal
hgtc to store the height of the Cylinder in decimal
Member functions/methods:
Cylinder(double r, double h) parameterized constructor to initialize
radius=r,
hgtc=h
double volume() to calculate volume of Cylinder [ volume
of a
Cuboid cylinder is 3.14*r*r*h]
Class name
Data members/instance variables:
length to store length of the cuboid in decimal
breadth to store breadth of the cuboid in decimal
height to store height of the cuboid in decimal
Member functions / methods
Cuboid(double l, double b, double h) parameterized constructor to
initialize
-length=l, breadth=b, height=h
double volume() to calculate volume of the
cuboid
[volume of a cuboid is
length*breadth]
interface Solid
{
public double volume(); //abstract method
}

class Cylinder implements Solid


{
double radius, hgtc;
Cylinder(double r, double h) //parameterized
constructor
{
radius=r;
hgtc=h;
}
public double volume() //returns the volume
of the Cylinder
{
return(3.14*radius*radius*hgtc);
}
}

class Cuboid implements Solid


{
double length, breadth, height;
Cuboid(double l, double b, double h)
//parameterized constructor
{
length=l;
breadth=b;
height=h;
}
public double volume() //returns the volume

of the Cuboid

{
return(length*breadth*height);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. radius double Stores radius of Cylinder
2. hgtc double Stores height of Cylinder
3. length double Stores length of Cuboid
4. breadth double Stores breadth of Cuboid
5. height double Stores height of Cuboid
RECURSION:-

Program 1:
Write a program to check whether the given number is a “Special
number” by using the concept of recursion.
Class name : Special
Data members :
int num: for storing the number.
int f : to find and to store the factorial of the number.
int sum : to store the sum of factorial of each digit.
Methods:
special ( ) : parameterized constructor.
int factorial(int a):to return the factorial of a number using the
recursive technique.
void digits( ) : to find the sum of factorial of each digit of num.
void display( ) : to print whether the number is a special number or not .
Also write the main( ) function to call other functions.

import java.util.*;
public class Special
{
int num,f,sum;
Special(int n) //parameterized constructor
{
num=n;
f=0;
sum=0;
}
int factorial(int a) //returns the factorial
of the number
{
if(a==0)
return 1;
else
return a*factorial(a-1);
}
int digits(int p) //finds the sum of
factorial of each digit of the number
{
int b=0;
while(p>0)
{
b=p%10;
sum=sum+factorial(b);
p=p/10;
}
return sum;
}
void display() //displays the conclusion
{
if(digits(num)==num)
System.out.println("SPECIAL NUMBER");
else
System.out.println("NOT A SPECIAL NUMBER");
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter a number");
n=sc.nextInt();
Special pc=new Special(n);
pc.display();
}
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. num int Stores the number entered by the
user
2. f int Stores factorial of a digit
3. sum int Stores sum of factorial of digits
4. n int Formal as well as actual parameter of
function Special()
5. a int Formal parameter of function
factorial()
6. p int Formal parameter of function digits()
7. b int Stores digits of p one by one
Program 2:
A disarium number is a number in which the sum of digits to the power
of their respective position is equal to the number itself. Example:

135 =1^1+ 3^2+ 5^3


= 1+9+125 = 135
So, 135 is a disarium number.
Design a class Disarium to check if a given number is a disarium
number or not.
Description of the members of class:
class : Disarium
Data members:
int num: stores number
int size: stores the size of the number.
Member methods:
Disarium (int nn): Parameterised constructor for
initializing num=nn & size=0
void countDigit( ): count total number of digits in the num
int sumOfDigits(int n, int p): returns the sum of the digits of the number
to the
power of their respective digits.
void check( ): checks whether the number is a disarium number or not
and prints an appropriate message accordingly.
import java.util.*;
public class Disarium
{
int num,size;
Disarium(int nn)
{
num=nn;
size=0;
}
void countDigits()
{
String s=Integer.toString(num);
size=s.length();
}
int sumOfDigits(int n,int p)
{
if(p==0)
return 0;
else
return
(int)Math.pow(n%10,p)+sumOfDigits(n/10,p-1);
}
void check()
{
int sum=sumOfDigits(num,size);
if(sum==num)
System.out.println("DISARIUM NUMBER");
else
System.out.println("NOT A DISARIUM
NUMBER");
}
public static void main(String args[])
{ int num;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
Disarium ds=new Disarium(num);
ds.countDigits();
ds.check();
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. num int To store the
number entered
by the user.
2. size int To store the
number of digits
3. s String To convert and
store number as
a String.
Program 3:
Design a class Pronic to check if a given number is a pronic number ornot.
[ A number is
said to be pronic if the product of two consecutive numbers is equal to
the number]
Example: 0 = 0 × 1
2=1×2
6=2×3
12=3×4
Thus, 0, 2, 6, 12... are pronic numbers.
Some of the members of the class are given below:
[10]
Class name : Pronic
Data members/instance variables:
num : to store a positive integer number
Methods / Member functions:
Pronic( ) : default constructor to initialize the
data member with legal initial value
void acceptnum( ) : to accept a positive integer number
boolean ispronic(int v) : returns true if the number ‘num’ is a
pronic number, otherwise returns false using recursive technique

void check( ) : checks whether the given number is a


pronic number by invoking the function ispronic()
and displays the result with an
appropriate message
Specify the class Pronic giving details of the constructor( ),
void acceptnum( ),
boolean ispronic(int) and void check( ). Define a main( ) function to
create an object and call the functions accordingly to enable the task.
import java.util.*;
public class Pronic
{
int num;
Pronic()
{
num=0;
}
void acceptnum()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter an integer");
num=sc.nextInt();
}
boolean ispronic(int v)
{
if(v*(v-1)==num)
return true;
if(v>1)
return ispronic(v-1);
return false;
}
void check()
{
if(ispronic(num)==true)
System.out.println("PRONIC NUMBER");
else
System.out.println("NOT A PRONIC NUMBER");
}
public static void main(String args[])
{
Pronic pr=new Pronic();
pr.acceptnum();
pr.check();
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. num int To store the
integer entered
by the user.
2. v int Used in checking
for pronic
numbers(by
product of
factors).
Program 4:
Write a program in java to ask the user to enter a sentence and reverse
that sentence without actually reversing it’s words (Using Recursion).

import java.util.Scanner;
public class Rev_Recur{
public static void main(String
args[]){Scanner in =new
Scanner(System.in);
//Input sentence
System.out.print("Enter a Sentence: ");
String sentence = in.nextLine();
//Reverse by calling the recursive method
String reversed = reverse(sentence);
//output the reversed word
System.out.print("Reverse: ");
System.out.println(reversed);
}
public static String reverse(String str)
{
int idx = str.indexOf(" ");
//Base condition - when str has only one
word
if(idx == -1)
return str;
//return after concatenating in reverse
order
return reverse(str.substring(idx+1))
+"" str.substring(0, idx);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. sentence String Stores the
sentence
entered by the
user.
2. reversed String Stores the
reversed
sentence.
3. idx int Stores index of
a single space.
Data structures:-

Program 1:
A linear data structure enables the user to add address from rear end
and remove address from front. Define a class Diary with the following
details: Class name : Diary
Data members / instance variables:
Q[ ] : array to store the addresses
size : stores the maximum capacity of the array
start : to point the index of the front end
end : to point the index of the rear end
Member functions:
Diary (int max) : constructor to initialize the data member size=max,
start=0 and end=0 void pushadd(String n) : to add address in the
diary from the rear end if possible, otherwise display the message “
NO SPACE”
String popadd( ) : removes and returns the address from the front end
of the diary if any, else returns “?????”
void show( ) : displays all the addresses in the diary
(a) Specify the class Diary giving details of the functions void
pushadd(String) and String popadd( ). Assume that the other functions have
been defined. The main function and algorithm need NOT be written.
(b) Name the entity used in the above data structure arrangement.
import java.util.*;
public class ISC2019Q11 {
public static void main(String[] args)
{
int max;
int choice = -1;
Scanner input = new Scanner(System.in);
System.out.println("Enter the maximum
strength of the diary:");
max = input.nextInt();
Diary obj = new Diary(max);
System.out.println("Enter 0 to exit:");
System.out.println("Enter 1 to add:");
System.out.println("Enter 2 to remove:");
System.out.println("Enter 3 to display:");
do {
System.out.println("Enter your choice:");
choice = input.nextInt(); switch(choice)

{case 0:
break;
case 1:
String n;
System.out.println("Enter the address
to add:");
n = input.next();
obj.pushAdd(n);
break;
case 2:
System.out.println(obj.popAdd());break;
case 3:
obj.show();
break;

}while(choice !=0);
input.close();
}
}
class Diary {
public void show() {
for(int i = start; i<end; i++)
System.out.println(Q[i]+" ");
}
public String popAdd()
{String frontValue;
if ( end == start)
return ("QUEUE IS EMPTY");
else {
frontValue = Q[start];
for(int i = 0; i < end-1 ;i++)
Q[i]=Q[i+1];
end--;
return (frontValue);
}
}
public void pushAdd(String n)
{if (end < size) {
Q[end] = n;
end++;
}
else
System.out.println("NO SPACE:");
}
Diary (int
max){ this.size =
max;this.start = 0;
this.end = 0;
Q = new String[this.size];
}
private String[] Q;
private int size;
private int start;
private int end;
}

VARIABLE DESCRIPTION TABLE


SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. Q String array to store the addresses

2. size int stores the maximum capacity of the


array

3. start int to point the index of the front end

4. end int to point the index of the rear end


Program 2:
Register is an entity which can hold a maximum of 100 names. The
register enables the user to add and remove names from the top most
end only. Define a class Register with the following details: Class name :
Register
Data members / instance variables:
stud[ ] array to store the names of the students
cap stores the maximum capacity of the array
top to point the index of the top end
Member functions:
Register (int max) constructor to initialize the data member
cap = max, top =
−1 and create the string array
void push(String n) to add names in the register at the top
location if possible,
otherwise display the message
“OVERFLOW”
String pop() removes and returns the names from the
top most location
of the register if any, else returns “$$”
void display() displays all the names in the register
(a) Specify the class Register giving details of the functions void
push(String) and String pop( ). Assume that the other functions have
been defined. The main function and algorithm need NOT be written.
(b) Name the entity used in the above data structure arrangement.

import java.util.*;
public class Register
{
String stud[];
int top,cap;
void push(String n) //adds the given element

in the Array

{
if(top==cap-1)
System.out.println(“OVERFLOW”);
else
{
top++;
stud[top]=n;
}
}
void pop() //removes the last element in the

array

{
if(top==-1)
{
System.out.println("$$");
return ;
}
else
{
int v=stud[top];
System.out.println("Element
popped:"+v);
top--;
}
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. stud String array to store the names of the
students

2. cap int stores the maximum capacity of the


array

3. top int to point the index of the top end


Program 3:
Write a menu driven program to implement a Linked List.
The menu must include following options:-
Main Menu:
1: Create Linked List Structure
2: Insert a list in the beginning
3: Insert a list in the end
4: Insert a list in the middle
5: Delete a list
6: Display a List
7: Exit
import java.util.*;
class node
{
int data;
node link;
node()
{
data=0;
link=null;
}
void create()
{
int n;
Scanner sc=new Scanner(System.in);
this.data=sc.nextInt();
System.out.println("Enter number of
nodes");
n=sc.nextInt();
node temp;
node ptr=this;
for(int i=1;i<n;i++)
{
temp=new node();
System.out.println("Enter next data");
temp.data=sc.nextInt(); temp.link=null;
ptr.link=temp;
temp=null;
ptr=ptr.link;
}
}
void insertBegin(node start, int x)
{
node temp=new node();
temp.data=x;
temp.link=null;
temp.link=start;
start=temp; temp=null;
}
void insertmid(node start, int x,int n)
{
node temp=new node();
temp.data=x;
temp.link=null;
node ptr=start;
int c=1;
while(c<n)
{
ptr=ptr.link;
c++;
}
temp.link=ptr.link;
ptr.link=temp;
}
void insertend(node start, int x)
{
node temp=new node();
temp.data=x;
temp.link=null;
node ptr=start;
while(ptr.link!=null)
{
ptr=ptr.link;
}
ptr.link=temp;
temp=ptr=null;
}
void delete(node start, int n)
{
node ptr=start;
node ptr1=ptr;
int c=1;
while(c<n)
{
ptr1=ptr;
ptr=ptr.link;
}
ptr1.link=ptr.link;
ptr.link=null;
}
void display(node start)
{
node ptr=start;
while(ptr!=null)
{
System.out.println(ptr.data);
ptr=ptr.link;
}
}
public static void main()
{
int k,p,ch;
Scanner sc=new Scanner(System.in);
node first=new node(); node abc=new
node();
do
{
System.out.println("Main Menu: ");
System.out.println("1: Create
Linked List Structure ");
System.out.println("2: Insert a list in
the beginning");
System.out.println("3: Insert a list in
the end");
System.out.println("4: Insert a list in
the middle");
System.out.println("5: Delete a list");
System.out.println("6: Display a
List");
System.out.println("7: Exit");
System.out.println("Enter your
choice");
ch=sc.nextInt();
switch(ch)
{
case 1:
first.create();
break;
case 2:
System.out.println("Enter data for
new node");
k=sc.nextInt();
first.insertBegin(first, k);
break;
case 3:
System.out.println("Enter data
for new node");
k=sc.nextInt();
first.insertend(first, k);
break;
case 4:
System.out.println("Enter data
for new node");
k=sc.nextInt();
System.out.println("Enter node
number
after node Insertion");
p=sc.nextInt();
first.insertmid(first,k,p);
break;
case 5:
System.out.println("Enter node
number
to be deleted");
k=sc.nextInt();
first.delete(first, k);
break;
case 6:
System.out.println("Data in the
linked list are: ");
first.display(first);
break;
}
}
while(ch!=7);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. data int To store data of
a list.
2. link node To store
address.
3. temp node Temporary node
4. ptr node Pointer
5. first node Refers starting
node
6. ch int Stored user’s
choice.
Date and time related:-

Program 1:
Write a program to accept date in the string format dd/mm/yyyy and
accept the name of the day on 1st January of the corresponding
year. Find the day for the given date.
import java.util.*;
public class date
{
public static void main(String args[])
{
String
ar[]={"MONDAY","TUESDAY","WEDNESDAY","THUSDAY","FRI
DAY","SATURDAY","SUNDAY","MONDAY","TUESDAY","WEDNES
DAY","THURSDAY","FRIDAY","SATURDAY"};
int
last[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int dd1, mm1, y1,a=0,s,f,g=0;
String d,day,dd,mm,y;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the date");
d=sc.nextLine();
dd=d.substring(0,2);
mm=d.substring(3,5);
y=d.substring(6);
dd1=Integer.parseInt(dd);
mm1=Integer.parseInt(mm);
y1=Integer.parseInt(y);
System.out.println("Enter the day on 1st
Jan");
day=sc.nextLine();
day=day.toUpperCase();
for(int i=0;i<mm1;i++) //calculates the
number of days
{
a=a+last[i];
}
a=a+dd1;
int n=a;
while(n>=7)
{
n=n-7;
}
for(int i=0;i<7;i++) //finds the index of
the day on 1st January in the array of names of
days
{
if(day.equals(ar[i]))
{
g=i;
break;
}

}
f=g+(n-1);
System.out.println(ar[f]);
}
}
VARIABLE DESCRIPTION TABLE
SERIAL NO. VARIABLE DATATYPE DESCRIPTION
NAME
1. ar String stores names of
days
2. last int Stores no. of
days of each
month
3. d String Stores the date
entered by user
4. day String Stores the day
on 1st January
5. dd String Stores date
6. mm String Stores month
7. y String Stores year
8. a int Stores after how
many days the
given date
occurs
9. f int Stores the index
of the final day
Program 2:
Write a program to input time in hours: minutes (12 hours format)
0<hours <12,
0<=minutes <60, and to convert the time in words and print the required
details.
Example:
06:45 QUARTER TO SEVEN
12:50 TEN MINUTES TO ONE
03:30 HALF PAST THREE
04:15 QUARTER PAST FOUR
import java.util.*;
public class Time
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,h;
String p="";
String
ar[]={"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"};
System.out.println("Enter hour");
h=sc.nextInt();
System.out.println("Enter minutes");
m=sc.nextInt();
if(h>0 && h<=12 && m>=0 && m<60)
{
if(m==0)
p=ar[h-1];
if(m<=30) //conditions for the
time in words if minutes are less than or equal to
30 {
if(m==15)
p="QUARTER PAST "+ar[h-1];
else if(m==30)
p="HALF PAST "+ar[h-1];
else if(m==1)
p=ar[m-1]+" MINUTE PAST "+ar[h-1];
else
p=ar[m-1]+" MINUTES PAST "+ar[h-1];
}
else //conditions for the time in words
if minutes are greater than 30
{
if(h==12) //if it's 12th hour
{
if(m==45)
p="QUARTER TO ONE";
else if(m==59)
p=ar[0]+" MINUTE TO ONE";
else
p=ar[59-m]+" MINUTES TO ONE";
}
else
{
if(m==45)
p="QUARTER TO "+ar[h];
else if(m==59)
p=ar[0]+" MINUTE TO "+ar[h];
else
p=ar[59-m]+" MINUTES TO "+ar[h];
}
}
System.out.println(p);
}
else
{
System.out.println("INVALID INPUT");
}
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NO. NAME
1. h int stores the hour
2. m int Stores the minutes
3. ar String Stores the string format for
numbers(1-60)
Object passing:-

Program 1:
A class Mixer has been defined to merge two sorted integer arrays in
ascending order. Some of the members of the class are given below:
[10] Class name: Mixer
Data members/instance variables:
int arr[ ]: to store the elements of an array
int n: to store the size of the array
Member functions:
Mixer(int nn): constructor to assign n=nn
void accept(): to accept the elements of the array in ascending
order without any duplicates
Mixer mix (Mixer A): to merge the current object array elements with
the parameterized array elements and return the resultant object void
display(): to display the elements of the array
Specify the class Mixer, giving details of the constructor(int), void
accept(), Mixer mix(Mixer) and void display(). Define the main( ) function
to create an object and call the function accordingly to enable the task
import java.util.*;
public class Mixer
{
int arr[];
int n;
Mixer(int nn)
{
n=nn;
arr=new int[n];
}
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter array elements");
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
}
Mixer Mix(Mixer A)
{
Mixer C =new Mixer(n+A.n);
int x,y,temp;
for(x=0;x<n;x++)
{
C.arr[x]=arr[x];
}
for(y=0;y<A.n;y++)
{
C.arr[x]=A.arr[y];
x++;
}
for(x=0;x<C.n-1;x++)
{
for(y=0;y<C.n-x-1;y++)
{
if(C.arr[y]>C.arr[y+1])
{
temp=C.arr[y];
C.arr[y]=C.arr[y+1];
C.arr[y+1]=temp;
}
}
}
return C;
}
void display()
{
System.out.println("\nARRAY ELEMENTS
ARE:-");
for(int i=0;i<n;i++)
System.out.print(arr[i]+” ”);
}
public static void main(String args[])
{
int l1,l2;
Scanner sc=new Scanner(System.in);
System.out.println("Enter length of 1st
array");
l1=sc.nextInt();
System.out.println("Enter length of 2st
array");
l2=sc.nextInt();
Mixer A=new Mixer(l1);
Mixer B=new Mixer(l2);
A.accept();B.accept();
A.display();B.display();
Mixer R=B.Mix(A);
System.out.println("\nMIXED ARRAY
IS:-");
R.display();
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. arr int Array to store
integers.
2. n int Stores length of
the array.
3. x int Looping
variable.
4. y int Looping
variable.
Program 2:
A class Merger concatenates two positive integers that are greater than
0 and produces a newly merged integer. [10]
Example: If the first number is 23 and the second is 764, then
the concatenated number will be 23764.
Some of the members of the class are given below:
Class name: Merger
Data members/instance variables:
n1: long integer to store the first number
n2: long integer to store the second number
mergNum: long integer to store the merged number
Member functions:
Merger(): constructor to initialize the data members
void readNum(): to accept the values of the data members n1 and
n2 voidjoinNum(): to concatenate the numbers n1 and n2 and store
it in mergNum
void show(): to display the original numbers and the merged number
with appropriate messages
Specify the class Merger giving the details of the constructor, void
readNum(), void joinNum() and void show(). Define the main() function
to create an object and call the functions accordingly to enable the task.
import java.util.*;
public class Merger
{
long n1,n2,mergnum;
Merger()
{
n1=0;
n2=0;
mergnum=0;
}
void readNum()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first number");
n1=sc.nextLong();
System.out.println("Enter the second
number");
n2=sc.nextLong();
}
void joinNum()
{
int n11,n22;
n11=(int)n1;
n22=(int)n2;
String m=Integer.toString(n11);
String n=Integer.toString(n22);
String s=m+n;
int f=Integer.parseInt(s);
mergnum=mergnum+f;
}
void show()
{
System.out.println("First number: "+n1);
System.out.println("Second number: "+n2);
System.out.println("Merged number:
"+mergnum);
}
public static void main(String args[])
{
Merger mg=new Merger();
mg.readNum();
mg.joinNum();
mg.show();
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. n1 int To store the first
number entered
by the user.
2. n2 int To store the
second number
entered by the
user.
3. mergnum int Stores the final
merged number.
Program 3:
The coordinates of a point P on a two-dimensional plane can be
represented by P(x, y) with x as the x-coordinate and y as the
oordinate. The coordinates of the midpoint of two points P1(x1, y1)
and P2(x2, y2) can be calculated as P(x, y) where: [10] x=(x1+x2)/2

y=(y1+y2)/2
Design a class Point with the following details:
Class name: Point
Data Members/instance variables:
x: stores the x-coordinate
y: stores the y-coordinate Member functions:
Point (): constructor to initialize x = 0, y = 0
void readpoint (): accepts the coordinates x and y of a point
Point midpoint (Point A, Point B): calculates and returns the midpoint
of the two points A and B
void displaypoint (): displays the coordinates of a point
Specify the class Point giving details of the constructor (), member
functions void readpoint ( ), Point midpoint (Point, Point) and void
displaypoint () along with the main () function to create an object and call
the functions accordingly to calculate the midpoint between any two
given points
import java.util.*;
public class Point
{
double x,y;
Point()
{
x=0.0d;
y=0.0d;
}
void readpoint()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter x and y coordinate
of the point respectively");
x=sc.nextDouble();
y=sc.nextDouble();
}
Point midpoint(Point A, Point B)
{
Point C=new Point();
C.x=(A.x+B.x)/2.0;
C.y=(A.y+B.y)/2.0;
return C;
}
void displaypoint()
{
System.out.println("Midpoint:
("+x+","+y+")");
System.out.println("X-coordinate: "+x+"\nY-
coordinate: "+y);
}
public static void main(String args[])
{
Point X=new Point();
Point Y=new Point();
Point Z=new Point();
X.readpoint();
Y.readpoint();
Z=X.midpoint(X,Y);
Z.displaypoint();
}
}
VARIABLE DESCRIPTION TABLE
SERIAL VARIABLE DATATYPE DESCRIPTION
NUMBER NAME
1. x double Stores
x-coordinate of
the point.
2. y double Stores
y-coordinate of
the point.
BIBLIOGRAPHY:

The ma e wri ec ic thic file hac beec takec fro+:-


❖ISC Compute Science Previouc Yea Questioc
Pape c.

❖ISC Compute Science Specimec Pape c.

❖ISC Prescribeθ Compute Science Textboo4.

You might also like