Class 11 Computer Project
Class 11 Computer Project
VIGNESH Chaturvedi
CLASS: 11
Subject:Computer Science
Stream: Science
Contents
No Program PageNo.
1 Pascal’s Triangle 1
2 Number in Words 3
3 AP Series 5
4 Spiral Matrix 8
5 Magic square 10
6 Linear Search 13
7 Binary Search 17
8 Selection Sort 20
9 Bubble sort 23
10 Decimal to Binary Number 26
11 Date Program 28
12 Star Pattern from enter string 31
13 Palindrome 33
14 Frequency of Each String Character 35
15 Word Search in String 38
16 Decoding of String 40
17 Number of Vowels and Consonants 43
18 Decimal to Roman 45
19 Celsius to fahrenheit 49
ACKNOWLEDGEMENTS
First of all, I’d like to thank my parents for helping me out with the
project.
Secondly, I’d like to thank our Computer teacher MD HADEES Sir
for helping us with the programs.
Lastly, I’m really grateful to whose help was imperative for myself
making this project.
PROGRAM 1
To Create Pascal’s Triangle
ALGORITHM
STEP 1 - START
STEP 2 - pas[0] = 1
STEP 3 - IF i=0 THEN GOTO STEP 4
STEP 4 - IF j=0 THEN GOTO STEP 5
STEP 5 - PRINT pas[j]+" "
STEP 6 - i++& IF i<n GOTO STEP 4
STEP 7 - j=0 & IF j<=i GOTO STEP 5
STEP 8 - IF j=i+1 THEN GOTO STEP 7
STEP 9 - pas[j]=pas[j]+pas[j-1]
STEP 10 - j--& IF j>0 GOTO STEP 9
STEP 11 – END
solution
import [Link].*;
class Pascal
{public void pascalw()throws IOException //pascalw() function
{BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link](“Enter a no.”);
int n=[Link]([Link]()); //accepting value
int [ ] pas = new int [n+1];
pas[0] = 1;
for (int i=0; i<n; i++) //loop evaluating the elements
{for (int j=0; j<=i; ++j)
[Link](pas[j]+" "); //printing the Pascal Triangle elements
[Link]( );
for (int j=i+1; j>0; j--)
pas[j]=pas[j]+pas[j-1];
}}}
Output
Solution
import [Link].*;
class Num2Words
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter any Number(less than 99)");
int amt=[Link]([Link]()); //accepting number
int z,g;
String x[]={“”,"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
String x1[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String x2[]={"","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
z=amt%10; //finding the number in words
g=amt/10;
if(g!=1)
[Link](x2[g-1]+" "+x1[z]);
else [Link](x[amt-9]);
}}
Output
solution
class APSeries
{private double a,d;
APSeries() //default constructor
{a = d = 0;
}
APSeries(double a,double d) //parameterized constructor
{this.a = a;
this.d = d;
}
double nTHTerm(int n) //final AP term
{return (a+(n-1)*d);
}
double Sum(int n) //function calculating sum
{return (n*(a+nTHTerm(n))/2);
}
void showSeries(int n) //displaying AP Series
{[Link]("\n\tSeries\n\t");
for(int i=1;i<=n;i++)
{[Link](nTHTerm(i)+" ");
}
[Link]("\n\tSum :"+Sum(n));
}
}
void main()throws IOException //main function
{BufferedReader br= new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter 1st term");
a=[Link]([Link]()); //accepting 1st term
[Link]("Enter Common difference");
d=[Link]([Link]()); //accepting common difference
[Link]("Enter [Link] terms");
int n=[Link]([Link]()); //accepting no. of terms
nTHTerm(n);
Sum(n);
showSeries(n);
}
output
9| I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 a int[][] main() spiral matrix
3 r int main() l/2
4 c int main() r-1
5 k1 int main() stores 2
6 k2 int main() stores 3
7 p int main() loop gate
8 co int main() coloumn index
9 re int main() row index
10 l int main() dimensions of thr matrix
11 ri int main() right side matrix loop varia ble
12 le int main() left side matrix loop variab le
13 dw int main() down side matrix loop vari able
14 up int main() up side matrix loop variable
15 y int main() loop variable to print matrix
16 yy int main() loop variable to print matrix
output
10 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 5
To Display Magic Square
ALGORITHM
STEP 1 - START
STEP 2 - arr[][]=new int[n][n],c=n/2-1,r=1,num
STEP 3 - IF num=1;num<=n*n;num++ GOTO STEP 4
STEP 4 - r--,c++
STEP 5 - IF r==-1 GOTO STEP 6
STEP 6 - r=n-1
STEP 7 - IF c>n-1 GOTO STEP 8
STEP 8 - c=0
STEP 9 - IF arr[r][c]!=0 GOTO STEP 10
STEP 10 - r=r+2 & c--
STEP 11 - num++ & IF num<=n*n GOTO STEP 4
STEP 12 - arr[r][c]=num
STEP 13 - IF r==0&&c==0 GOTO STEP 14
STEP 14 - r=n-1, c=1 & arr[r][c]=++num
STEP 15 - IF c==n-1&&r==0 GOTO STEP 16
STEP 16 - arr[++r][c]=++num
STEP 17 - PRINT ()
STEP 18 - IFr=0 GOTO STEP 19
STEP 19 - IF c=0 GOT STEP 20
STEP 20 - PRINT arr[r][c]+" " & ()
STEP 21 - c++ & IF c<n GOTO STEP 20
STEP 21 - r++ & r<n GOTO STEP 19
STEP 22 – END
solution
/*A Magic Square is a square whose sum of diagonal elements, row elements and coloumn
elements is the same*/
import [Link].*;
class MagicSquare
{public static void main(String args[])throws Exception //main function
{BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("enter the dimension of magical square=");
int n = [Link]([Link]()); //accepting dimensions
int arr[][]=new int[n][n],c=n/2-1,r=1,num;
for(num=1;num<=n*n;num++) //loop for finding magic square elements
{r--;
c++;
if(r==-1)
r=n-1;
if(c>n-1)
c=0;
if(arr[r][c]!=0)
{r=r+2;
c--;
}
arr[r][c]=num;
if(r==0&&c==0)
{r=n-1;
c=1;
arr[r][c]=++num;
}
if(c==n-1&&r==0)
arr[++r][c]=++num;
}
[Link]();
for(r=0;r<n;r++) //loop displaying magic square
{for(c=0;c<n;c++)
[Link](arr[r][c]+" ");
[Link]();
}}}
11| I S C C o m p u t e r S c i e n c e P r o j e c
variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 n Int main() input dimensions
3 arr int[][] main() magic square matrix
4 num Int main() loop variable for magic sq uare
5 r Int main() Row
6 c Int main() Coloumn
output
PROGRAM 6
To Search an Array Using
Linear Search
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n REPEAT STEP 7
STEP 7 - IF (a[i] == v) THEN flag =i
STEP 8 - IF (flag=-1) THEN GOTO STEP 9 OTHERWISE GOTO STEP 10
STEP 9 - PRINT “ not found”
STEP 10 - PRINT v+" found at position - "+flag
STEP 11 – END
13 | I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
class LinearSearch
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new InputStreamReader([Link]));
public LinearSearch(int nn)
{n=nn;
}
public void input() throws IOException //function for obtaining values from user
{[Link]("enter elements");
for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
public void display() //function displaying array values
{[Link]();
for(i=0;i<n;i++)
{[Link](a[i]+" ");
}}
public void search(int v) //linear search function
{int flag=-1;
for(int i=0; i<n ; i++)
{if(a[i] == v)
flag =i;
}
if(flag== -1 )
[Link]("not found");
else [Link](v+" found at position - "+flag);
}
public static void main(String args[]) throws IOException //main function
{LinearSearch obj = new LinearSearch(10);
[Link]();
[Link]();
[Link]("enter no. to be searched -"); //accepting the values to be searched
int v = [Link]([Link]());
[Link](v);
}}
15 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader - BufferedReader o bject
2 n int - array length
3 i int - loop variable
4 a[] int[] - input array
5 nn int LinearSearch() parameter in constructor
6 v int search(), main() search element
7 flag int search() flag
8 obj LinearS earch main() LinearSearch obje ct
output
16 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 7
To Search an Array Using
Binary Search
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1 , l=0, u=n-1
STEP 6 - IF(l<=u && flag=-1) REPEAT STEP 7 AND Step 8
STEP 7 - m = (l+u)/2
STEP 8 - IF (a[m] == v) THEN flag =m OTHERWISE GOTO STEP 9
STEP 9 - IF (a[m] < v) THEN l = m+1 OTHERWISE u =m-1
STEP 10 - IF (flag=-1) THEN GOTO STEP 11 OTHERWISE GOTO STEP 12
STEP 11 - PRINT “ not found”
STEP 12 - PRINT v+" found at position - "+flag
STEP 13 - END
17| I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
class BinarySearch
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new InputStreamReader([Link]));
public BinarySearch(int nn) //default constructor
{n=nn;
}
public void input() throws IOException //function accepting array elements
{[Link]("enter elements");
for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
public void display() //displaying array elements
{[Link]();
for(i=0;i<n;i++)
{[Link](a[i]+" ");
}}
public void search(int v) //function to search array elements using binary search
technique
{int l=0;
int u = n-1;
int m;
int flag=-1;
while( l<=u && flag == -1)
{m = (l+u)/2;
if(a[m] == v)
flag = m;
else if(a[m] < v)
l = m+1;
else u = m-1;
}
if(flag== -1 )
[Link]("not found");
else [Link](v+" found at position - "+flag);
}
public static void main(String args[]) throws IOException //main function
{BinarySearch obj = new BinarySearch(10);
[Link]();
[Link]();
[Link]("enter no. to be searched -");
int v = [Link]([Link]()); //accepting integer to be searched by binary search
[Link](v);
18 | I S C C o m p u t e r S c i e n c e P r o j e c t
}}
output
19| I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 8
To Sort an array Using
Selection Sort
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 11
STEP 7 - min =i
STEP 8 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 9 - IF(a[j]<a[min]) then min =j
STEP 10 - IF (min!=i) GOTO STEP 11
STEP 11 - temp = a[i], a[i] =a[min], a[min] = temp
20 | I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
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([Link]));
[Link]("enter elements");
for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
public void display() //function displaying array elements
{[Link]();
for(i=0;i<n;i++)
{[Link](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);
[Link]();
[Link]("Before sorting - ");
[Link]();
[Link]("After sorting - ");
[Link]();
[Link]();
}}
21 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader input() BufferedReader object
2 n int - array length
3 i int - loop variable
4 a[] int[] - input array
5 nn int SelectionSort() parameter in constructor
6 j int sort() sort index
7 temp int sort() temporary storage
8 min int sort() minimum value
9 x Selecti onSort main() SelectioSort object
output
22 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 9
To Sort an Array Using
Bubble Sort
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM i=0 to i<n REPEAT STEP 4
STEP 4 - PRINT a[i]+" "
STEP 5 - flag=-1
STEP 6 - FROM i=0 to i<n-1 REPEAT STEP 7 to STEP 9
STEP 7 - FROM j=i+1 to j<n REPEAT STEP 8
STEP 8 - IF(a[j] > a[j+1]) THEN GOTO STEP 9
STEP 9 - temp = a[i], a[i] =a[min], a[min] = temp
STEP 10 - END
23 | I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
class BubbleSort
{int n,i;
int a[] = new int[100];
public BubbleSort(int nn) //parameterized constructor
{n=nn;
}
public void input() throws IOException //function accepting array elements
{BufferedReader br =new BufferedReader(new InputStreamReader([Link]));
[Link]("enter elements");
for(i=0;i<n;i++)
{a[i] = [Link]([Link]());
}}
public void display() //function displaying array elements
{[Link]();
for(i=0;i<n;i++)
{[Link](a[i]+" ");
}}
public void sort() //function sorting array elements using Bubble Sort technique
{int j,temp;
for(i=0 ; i<n-1 ; i++)
{for(j=0 ; j<n-1-i ; j++)
{if(a[j] > a[j+1])
{temp = a[j];
a[j] =a[j+1];
a[j+1] = temp;
}}}}
public static void main(String args[]) throws IOException //main function
{BubbleSort x = new BubbleSort(5);
[Link]();
[Link]("Before sorting - ");
[Link]();
[Link]("After sorting - ");
[Link]();
[Link]();}}
24 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader input BufferedReader object
2 n int - array length
3 i int - loop variable
4 a[] int[] - input array
5 nn int BubbleSort() parameter in construc tor
6 j int sort() sort index
7 temp int sort() temporary storage
8 x Selecti onSort main() SelectionSort object
output
25 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 10
To Convert a Decimal no. Into
its Binary Equivalent
ALGORITHM
STEP 1 - START
STEP 2 - n = 30
STEP 3 - INPUT int no
STEP 4 - c =0 , temp = no
STEP 5 - IF (temp!=0) REPEAT STEP 6
STEP 6 - a[c++] = temp%2, temp = temp / 2
STEP 7 - FROM i=c-1 to i>0 REPEAT STEP 8
STEP 8 - PRINT a[i]
STEP 9 – END
solution
import [Link].*;
class Dec2Bin
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new InputStreamReader([Link]));
public Dec2Bin(int nn) //parameterized contructor
{n=nn;
}
public void dectobin(int no) //function converting decimalto binary number
{int c = 0;
int temp = no;
while(temp != 0)
{a[c++] = temp % 2;
temp = temp / 2;
}
[Link]("Binary eq. of "+no+" = ");
for( i = c-1 ; i>=0 ; i--) //Displaying binary number
[Link]( a[ i ] );
26 | I S C C o m p u t e r S c i e n c e P r o j e c t
}
public static void mai n(String args[]) throws IOException // main function
{Dec2Bin obj = new D ec2Bin(30);
[Link](" enter decimal no -
"); int no = [Link]
eInt([Link]()); [Link](no);
}}
variable description
No. Name Type Method Description
1 br Buffere dReader BufferedReader object
2 n int - array length
3 i int - loop variable
4 a[] int[] - array storing bi nary no.
5 nn int Dec2Bin() parameter in constructor
6 no int main(), dectobin() input number
7 temp int dectobin() temporary stora ge
8 c int dectobin() counter
9 obj Dec2Bin main() Dec2Bin object
output
27 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 11
To Display Date From
Entered Day Number
ALGORITHM
STEP 1 - START
STEP 2 - INITIALISE a[ ] , m[ ]
STEP 3 - INPUT n , yr
STEP 4 - IF ( yr%4=0) THEN a[1] = 29
STEP 5 - t =0 , s = 0
STEP 6 - IF ( t<n) REPEAT STEP 7
STEP 7 - t =t + a[s++]
STEP 8 - d = n + a[--s] - t
STEP 9 - IF ( d ==1|| d == 21 || d == 31 ) then PRINT d + "st" + m[s] +
" , "+yr
STEP 10 - IF ( d ==2|| d == 22 ) then PRINT d + "nd" + m[s] + " , "+yr
STEP 11 - IF ( d ==3|| d == 23 ) then PRINT d + "rd" + m[s] + " , "+yr
OTHERWISE GOTO STEP 12
STEP 12 - PRINT d + "th" + m[s] + " , "+yr
STEP 13 – END
28 | I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
class Day2Date
{static BufferedReader br =new BufferedReader(new InputStreamReader([Link]));
public void calc(int n, int yr) //function to calculate date
{int a[ ] = { 31,28,31,30,31,30,31,31,30,31,30,31 } ;
String m[ ] = { "Jan", "Feb", "Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" } ;
if ( yr % 4 == 0)
a[1] =29;
int t=0,s=0;
while( t < n) //loop calculating date
{t =t + a[s++];
}
int d = n + a[--s] - t;
if( d == 1|| d == 21 || d == 31 )
{[Link]( d + "st" + m[s] + " , "+yr);
}
if( d == 2 || d == 22 )
{[Link]( d + "nd" + m[s] + " , "+yr);
}
if( d == 3|| d == 23 )
{[Link]( d + "rd" + m[s] + " , "+yr);
}
else {[Link]( d + "th" + m[s] + " , "+yr);
}}
public static void main(String args[]) throws IOException //main function
{Day2Date obj = new Day2Date();
[Link]( "Enter day no = "); //accepting day no.
int n = [Link]([Link]());
[Link]( "Enter year = "); //accepting year
int yr = [Link]([Link]());
[Link](n,yr);
}}
29 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader - BufferedReader obje ct
2 n int calc(), main() Day number
3 yr int calc(), main() year
4 a int[] calc() array storing day
5 m int[] calc() array storing month
6 t int calc() array index
7 s int calc() array index
8 d int calc() n+a[--s]+t
9 obj Day2D ate main() Day2Date object
output
30 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 12
To Create a Star Pattern
From Entered String
solution
import [Link].*;
class Pattern
{public static void main (String args[]) throws IOException
{int i,sp,j,k,l;
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("enter the string ="); //accepting string
String s = [Link]();
l=[Link]();
/*printing the pattern*/
for(i=0;i<l;i++)
if(i==l/2)
[Link](s);
else {sp=[Link]((l/2)-i);
for(j=sp;j<l/2;j++)
[Link](" ");
k=0;
while(k<3)
{[Link]([Link](i));
for(j=0;j<sp-1;j++)
[Link](" ");
k++;
}
[Link](" ");
}}}
31 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 s String main() input string
3 i int main() loop variable for printing the pattern
4 sp int main() [Link]((l/2)-i)
5 j int main() loop variable for printing the pattern
6 k int main() loop variable for printing the pattern
7 l int main() length of string
output
32 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 13
To Check if Entered String is
Palindrome or Not
ALGORITHM
STEP 1 - START
STEP 2 - INPUT string s
STEP 3 - StringBuffer sb =
s STEP 4 - [Link]
STEP 5 - String rev = sb
STEP 6 - IF rev = s GOTO STEP 7 OTHERWISE GOTO STEP 8
STEP 7 - PRINT " Palindrome"
STEP 8 - PRINT " Not Palindrome"
STEP 9 – END
solution
import [Link].*;
class Palindrome
{public static void main(String args[]) throws IOException //main function
{BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("enter the string=");
String s = [Link](); //accepting the string
StringBuffer sb = new StringBuffer(s);
[Link](); //reversing the string
String rev = new String(sb);
if([Link](rev)) //checking for palindrome
[Link]("Palindrome " ); //displaying the result
else [Link]("Not Palindrome " );
}}
33 | I S C C o m p u t e r S c i e n c e P r o j e c t
varia ble description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 s String main() input string
3 sb StringBuffer main() StringBuffer object of s
4 rev String main() revese string
output
34 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 14
To Display a Frequency of
Each Character in Entered
String
ALGORITHM
STEP 1 - START
STEP 2 - INPUT str
STEP 3 - l=[Link]()
STEP 4 - PRINT str
STEP 5 - IF i=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 6 - char a=[Link](i)
STEP 7 - IF ii=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 8 - char b = [Link](ii)
STEP 9 - IF a==b GOTO STEP 10
STEP 10 - freq=freq+1
STEP 11 - ii++ & IF ii<1 GOTO STEP 8
STEP 12 - i++ & IF i<1 GOTO STEP 6
STEP 13 - DISPLAY a+" occurs "+freq+" times"
STEP 14 – END
35 | I S C C o m p u t e r S c i e n c e P r o j e c t
solution
import [Link].*;
class Frequency
{private int i,a1,l,p,j,freq;
public Frequency() //default constructor
{p=0;
freq=0; // initialise instance variables
}
public void count(String str) //counting character frquency
{int ii;
l=[Link]();
[Link](str);
for(i=0;i<l;i++)
{char a=[Link](i);
for(ii=0;ii<l;ii++)
{char b = [Link](ii);
if (a==b)
freq=freq+1;
}
[Link](a+" occurs "+freq+" times"); //displaying frequency
freq=0;
}}
public static void main(String args[]) throws IOException //main function
{BufferedReader br =new BufferedReader(new
InputStreamReader([Link])); [Link]("enter string");
String str = [Link]();
Frequency x = new Frequency();
[Link](str);
}}
36 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
Metho
No. Name Type d Description
Buffere
1 br dReader main() BufferedReader object
2 i int - loop variable
3 a1 int - instance variable
4 l int - length of string
5 p int - instance variable
6 freq int - frequency of characters
7 ii int count() loop variable
8 a char count() character at index i
9 b char count() character at index ii
10 str String main() input string
11 x Frequency main() Frequency object
OUTPUT
37 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 15
To Find a Word in Entered
String
ALGORITHM
STEP 1 - START
STEP 2 - INPUT string s
STEP 3 - StringTokenizer st = s
STEP 4 - l =[Link]()
STEP 5 - INPUT look
STEP 6 - flag = -1
STEP 7 - IF ([Link]()) REPEAT STEP 8
STEP 8 - IF ([Link]([Link]())) THEN flag =1
STEP 9 - IF flag = - 1 GOTO STEP 10 OTHERWISE STEP 11
STEP 10 - PRINT "word not found"
STEP 11 - PRINT "word found"
STEP 12 – END
solution
import [Link];
import [Link].*;
public class WordSearch
{public static void main(String[] args) throws IOException //main function
{BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("enter the string=");
String s = [Link](); //accepting string
StringTokenizer st = new StringTokenizer(s," "); //StringTokenizer initialization
[Link]("enter the word to be searched =");
String look = [Link]();
int flag = -1;
while([Link]()) //searching for word
{if([Link]([Link]()))
flag =1;
38 | I S C C o m p u t e r S c i e n c e P r o j e c t
}
if(flag ==-1)
{[Link]("the word not found"); //display ing the result
}
else {
[Link]("t he word found");
}}}
variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 s String main() input string
3 st StringTokenizer main() StringTokenizer object
4 look String main() word to be searched
5 flag int main() Flag
output
39 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 16
To Decode the Entered String
ALGORITHM
STEP 1 - START
STEP 2 - INPUT name, n
STEP 3 - l=[Link]()
STEP 4 - PRINT original string is "+name
STEP 5 - IF i=0 THEN GOTO STEP 6
STEP 6 - char c1=[Link](i)
STEP 7 - c=(int)c1
STEP 8 - IF n>0 THEN GOTO STEP 9 THERWISE GOTO STEP 12
STEP 9 - IF (c+n)<=90 THEN GOTO STEP 10 OTHERWISE GOTO STEP 11
STEP 10 - PRINT (char)(c+n)
STEP 11 - c=c+n;c=c%10,c=65+(c-1) & PRINT (char)(c)
STEP 12 - ELSE IF n<0 THEN GOTO STEP 13 OTHERWISE GOTO STEP 19
STEP 13 - n1=[Link](n)
STEP 14 - IF (c-n1) >=65 THEN GOTO STEP 15 OTHERWISE GOTO STEP 16
STEP 15 - DISPLAY (char) (c-n1)
STEP 16 - IF c>65 THEN GOTO STEP 17 OTHERWISE GOTO STEP 18
STEP 17 - c=c-65,
STEP 18 - c=n1 & PRINT (char)(90-(c-1))
STEP 19 - ELSE IF n==0
STEP 20 - DISPLAY "no change "+name
STEP 21 - END
solution
import [Link].*;
class Decode
{public void compute()throws IOException //compute() function
{BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link](“Enter name:”);
String name=[Link]();
[Link](“Enter number:”);
int n=[Link]([Link]());
int j,i,l,c=0,y,n1;
l=[Link]();
40| I S C C o m p u t e r S c i e n c e P r o j e c t
[Link]("original string is "+name);
for(i=0;i<l;i++)
{char c1=[Link](i);
try //trying for NumberFormatException
{c=(int)c1 ;
}
catch(NumberFormatException e)
{}
if(n>0)
{if((c+n)<=90)
/*Decoding String*/
[Link]((char)(c+n));
else {c=c+n;
c=c%10;
c=65+(c-1);
[Link]((char)(c));
}}
else if(n<0)
{n1=[Link](n);
if((c-n1) >=65)
[Link]((char) (c-n1));
else {if(c>65)
c=c-65;
else c=n1;
[Link]((char)(90-(c-1)));
}}
else if (n==0)
{[Link]("no change "+name);
break;
}}}}
41| I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader compute() BufferedReade r object
2 name String compute() input string
3 n int compute() decode numbe r
4 j int compute() loop variable
5 i int compute() loop variable
6 l int compute() length of string
7 c int compute() ASCII of c1
8 y int compute()
9 n1 int compute()
10 c1 char compute() character at index i
11 e Numbe rFormatException compute() NumberFOrma tException object
output
42 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 17
To Create a String and Count
Number of Vowels and
Consonants
ALGORITHM
STEP 1 - START
STEP 2 - a = "Computer Applications"
STEP 3 - z = [Link]()
STEP 4 - x= 0 , b= 0
STEP 5 - FROM y =0 to y<z REPEAT STEP 6
STEP 6 - IF ([Link](y)=='a'||[Link](y)=='e'||[Link](y)=='i'||[Link](y)=='o'||[Link](y)=='u') THEN x =x +1 OTHERWISE b = b+1
STEP 7 - PRINT x
STEP 8 - PRINT b
STEP 9 – END
solution
import [Link].*;
class Vowels
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter a string");
String a= [Link](); //Accepting string
int z=[Link](),y,x=0,b=0;
for(y=0;y<z;y++) //loop for counting number of vowels
{if([Link](y)=='a'||[Link](y)=='e'||[Link](y)=='i'||[Link](y)=='o'||[Link](y)=='u')
x++;
else b++;
}
[Link]("Number of vowels in string ="+x); //displaying result
[Link]("Number of consonants in string ="+b);
}}
43 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 br Buffere dReader main() BufferedReader object
2 a String main() input string
3 z Int main() length of string
4 y Int main() loop variable
5 b Int main() no. of consonants
6 x Int main() no. of vowels
output
44 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 18
To Convert a Decimal
Number to a Roman Numeral
ALGORITHM
STEP 1 – START
STEP 2 – Enter number num
STEP 3 -- hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}
STEP 4 -- ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
STEP 5 -- unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
STEP 6 – Display hund[num/100] and ten[(num/10)%10] and unit[num%10]
STEP 7 – END
solution
import [Link].*;
public class Dec2Roman
{public static void main() throws IOException //main function
{DataInputStream in=new DataInputStream([Link]);
[Link]("Enter Number : ");
int num=[Link]([Link]()); //accepting decimal number
String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
/*Displaying equivalent roman number*/
[Link]("Roman Equivalent= "+hund[num/100]+ten[(num/10)%10]+unit[num%10]);
}}
45 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable description
No. Name Type Method Description
1 in DataIn putStream main() DataInputStream object
2 num int main() input number
3 hund String[] main() array storing 100th positi on
4 ten String[] main() array storing 10th positio n
5 unit String[] main() array storing units positio n
output
46 | I S C C o m p u t e r S c i e n c e P r o j e c t
PROGRAM 19
To Convert Celsius into
Fahrenheit Using Inheritence
ALGORITHM
STEP 1 – START
STEP 2 -- Input temperature ‘celcius’ in celcius
STEP 3 – far=1.8*celcius + 32
STEP 4 – Display far
STEP 5 -- END
Solution
import [Link].*;
class C2F
{ public static void main(String args[])throws IOException //main function
{Temperature ob= new Temperature();
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter temperature in Celsius"); //accepting temperature
double temp=[Link]([Link]([Link]()));
[Link]("The temperature in fahrenheit is = "+temp);
}}
class Temperature extends C2F
{double convert(double celcius) //function to convert Celsius to fahrenheit
{double far=1.8*celcius+32.0;
return far;
}}
47 | I S C C o m p u t e r S c i e n c e P r o j e c t
variable
description
No. Name Type Method Description
1 br BufferedReader main() BufferedReader object
2 ob C2F main() C2F object
3 temp double main() calculated Fahrenheit te mperature
4 celcius double convert() input temperature in Celsius
5 far double convert() Calculated Fahrenheit temperature
output
48 | I S C C o m p u t e r S c i e n c e P r o j e c t