You are on page 1of 56

Computer

Science
Project

For ISC
Programming
In Blue J
Ishu Verma
12 A
Sherwood Academy
ACKNOWLEDGEMENT
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 teachers Satyendra Sahu
sir for helping us with the programs.

Lastly, I’m really grateful to my


friend Manisha Gupta whose help
was imperative for myself making
this project.
Content
No. Program
1 Pascal’s Triangle
2 Number in Words
3 AP Series
4 Calendar of Any Month
5 Factorial (Using Recursion)
6 Fibonacci Series (Using Recursion)
7 GCD (Using Recursion)
8 Spiral Matrix
9 Magic Square
10 Linear Search
11 Binary Search
12 Selection Sort
13 Bubble Sort
14 Decimal to Binary Number
15 Palindrome Check
16 Word Search in String
17 Number of Vowels and Consonants
18 Word Count
19 Sales Commission
20 Celsius to Fahrenheit (Using Inheritance)
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 java.io.*;
class Pascal
{public void pascalw()throws IOException
//pascalw() function
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(“Enter a no.”);
int n=Integer.parseInt(br.readLine());
//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)
System.out.print(pas[j]+" ");
//printing the Pascal Triangle elements
System.out.println( );
for (int j=i+1; j>0; j--)
pas[j]=pas[j]+pas[j-1];
}}}

output
PROGRAM 2
To Display Entered Number
in Words

ALGORITHM
STEP 1 - START
STEP 2 - INPUT amt
STEP 3 - z=amt%10 , g=amt/10
STEP 4 - IF g!=1 THEN GOTO STEP 5 OTHERWISE
GOTO STEP 6
STEP 5 - PRINT x2[g-1]+" "+x1[z]
STEP 6 - PRINT x[amt-9]
STEP 7 – END

solution
import java.io.*;
class Num2Words
{public static void main(String args[])throws IOException
//main function
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter any Number(less than 99)");
int amt=Integer.parseInt(br.readLine());
//accepting number
int z,g;
String
x[]={“”,"Ten","Eleven","Twelve","Thirteen","Fourteen","Fi
fteen","Sixteen","Seventeen","Eighteen","Nineteen"};
String
x1[]={"","One","Two","Three","Four","Five","Six","Seven
","Eight","Nine"};
String
x2[]={"","Twenty","Thirty","Fourty","Fifty","Sixty","Seve
nty","Eighty","Ninety"};
z=amt%10;
//finding the number in words
g=amt/10;
if(g!=1)
System.out.println(x2[g-1]+" "+x1[z]);
else System.out.println(x[amt-9]);
}}

output
PROGRAM 3
To Display A.P. Series and
Its Sum

ALGORITHM
STEP 1 - START
STEP 2 - a = d = 0
STEP 3 - IMPORT a, d
STEP 4 - this.a = a & this.d = d
STEP 5 - IMPORT n
STEP 6 - RETURN (a+(n-1)*d)
STEP 7 - IMPORT n
STEP 8 - RETURN (n*(a+nTHTerm(n))/2)
STEP 9 - IMPORT n
STEP 10 - PRINT \n\tSeries\n\t"
STEP 11 - IF i=1;i<=n;i++ GOTO STEP 12
STEP 12 - PRINT nTHTerm(i)+" "
STEP 13 - i++ & IF i<=n GOTO STEP 12
STEP 14 - PRINT n\tSum : "+Sum(n)
STEP 15 – END

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
{System.out.print("\n\tSeries\n\t");
for(int i=1;i<=n;i++)
{System.out.print(nTHTerm(i)+" ");
}
System.out.print("\n\tSum :"+Sum(n));
}
}
void main()throws IOException
//main function
{BufferedReader br= new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter 1st term");
a=Integer.parseInt(br.readLine());
//accepting 1 st term
System.out.println("Enter Common difference");
d=Integer.parseInt(br.readLine());
//accepting common difference
System.out.println("Enter no.of terms");
int n=Integer.parseInt(br.readLine());
//accepting no. of terms
nTHTerm(n);
Sum(n);
showSeries(n);
}

output
PROGRAM 4
To Display Calendar of Any
Month of Any Year

ALGORITHM
STEP 1 - START
STEP 2 - INPUT int month,int year
STEP 3 - int i,count=0,b,c,d=1 & String w="SMTWTFS"
STEP 4 - IF (year%100==0 && year%400==0) || (year
%100!=0 && year%4==0)
STEP 5 - days[1]=29
STEP 6 - PRINT "================The Calendar
of"+month1[month-1]+"
"+year+"is==================")
STEP 7 - IF i=0 THEN GOTO STEP 8
STEP 8 - PRINT (i)+"\t" & " "
STEP 9 - IF i=1 GOTO STEP 10
STEP 10 - IF (year%100==0 && year%400==0) || (year
%100!=0 && year%4==0)THEN GOTO STEP
11OTHERWISE GOTO STEP 12
STEP 11 - count+=2
STEP 12 - count+=1
STEP 13 - IF i=0 GOTO STEP 14
STEP 14 - count+=days[i] , count+=1, count%=7 & b=7-
count
STEP 15 - IF b!=1 || b!=7 GOTO STEP 16
STEP 16 - IF count>0 GOTO STEP 17,18
STEP 17 - PRINT ' '+"\t")
STEP 18 - count--
STEP 19 - IF i=1 GOTO STEP 20
STEP 20 - IF b>0 && IF d<=days[month-1] GOTO STEP
21,22
STEP 21 - PRINT d+"\t"
STEP 22 - d++ & b--
STEP 23 - b=7
STEP 24 - i++ & IF i<MONTH GOTO STEP14
STEP 25 - PRINT " "
STEP 26 – END

solution

import java.io.*;
class Calendar
{public void dee()throws IOException
//dee() function
{int i,count=0,b,d=1;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(“Enter month”);
//accepting month and year
int month=Integer.parseInt(br.readLine());
System.out.println(“Enter Year”);
int year=Integer.parseInt(br.readLine());
/* Computing and displaying calendar*/
String w="SMTWTFS";
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
String
month1[]={"January","February","March","April","May","
June","July","August","September","October","November"
,"December"};
if((year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0))
days[1]=29;
System.out.println("================The Calendar
of"+month1[month-1]+"
"+year+"is==================");
for(i=0;i<w.length();i++)
System.out.print(w.charAt(i)+"\t");
System.out.println(" ");
for(i=1;i<year;i++)
if((year%100==0 && year%400==0) || (year%100!=0 &&
year%4==0))
count+=2;
else count+=1;
for(i=0;i<month;i++)
count+=days[i];
count+=1;
count%=7;
b=7-count;
if(b!=1 || b!=7)
while(count>0)
{System.out.print(' '+"\t");
count--;
}
for(i=1;i<7;i++)
{while(b>0 && d<=days[month-1])
{System.out.print(d+"\t");
d++;
b--;
}
b=7;
System.out.println(" ");
}}}

output
PROGRAM 5
To Calculate Factorial Using
Recursion

ALGORITHM
STEP 1 - START
STEP 2 - INPUT n
STEP 3 - IF(n<2) THEN return 1 OTHERWISE return (n *
fact(n-1))
STEP 4 – END
solution
import java.io.*;
class Factorial
{public static void main(String args[]) throws IOException
//main function
{BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter no =");
int n = Integer.parseInt(br.readLine());
//accepting no.
Factorial obj = new Factorial();
long f = obj.fact(n);
System.out.println("Factorial ="+f);
//displaying factorial
}
public long fact(int n)
//recursive fact()
{if(n<2)
return 1;
else return (n*fact(n-1));
}}

output
PROGRAM 6
To Display Fibonacci Series
Using Recursion

ALGORITHM
STEP 1 - START
STEP 2 - INPUT n
STEP 3 - IF(n<=1) THEN return 1 OTHERWISE return
(fib(n-1) +fib(n-2))
STEP 4 – END
solution
import java.io.*;
class Fibonacci
{public static void main(String args[]) throws IOException
//main function
{Fibonacci obj = new Fibonacci();
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter no of term =");
//accepting no. of terms
int n = Integer.parseInt(br.readLine());
System.out.println();
for(int i=1;i<=n;i++)
//Fibonacci element display loop
{int f = obj.fib(i);
System.out.print(f+" ");
}}
public int fib(int n)
//Recursive function fib() for calculation of Fibonacci
element
{if(n<=1)
return n;
else
return (fib(n-1) +fib(n-2));
}}

output
PROGRAM 7
To Calculate GCD Using
Recursion

ALGORITHM
STEP 1 - START
STEP 2 - INPUT p,q
STEP 3 - IF(q=0) THEN return p OTHERWISE return
calc(q,p%q)
STEP 4 – END

solution
import java.io.*;
class GCD
{public static void main(String args[]) throws
IOException //main function
{BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the numbers =");
int p = Integer.parseInt(br.readLine()); //accepting nos.
int q = Integer.parseInt(br.readLine());
GCD obj = new GCD();
int g = obj.calc(p,q);
System.out.println("GCD ="+g);
}
public int calc(int p,int q)
//recursive function calculating GCD
{if(q==0)
return p;
else return calc(q,p%q);
}}

output
PROGRAM 8
To Display Spiral Matrix.

ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[][]
STEP 3 - IF p!=(int)Math.pow(l,2) GOTO STEP 4
STEP 4 - IF co!=0 GOTO STEP 5
STEP 5 - re=1
STEP 6 - IF ri=1;ri<=k1-re;ri++ GOTO STEP 7
STEP 7 - p++,c++
STEP 8 - IF c==l GOTO STEP 9
STEP 9 - BREAK
STEP 10 - a[r][c]=p
STEP 11 - IF c==l GOTO STEP 12
STEP 12 - BREAK
STEP 13 - IF dw=1 GOTO STEP 14
STEP 14 - p++,r++,a[r][c]=p
STEP 15 - IF le=1 GOTO STEP 16
STEP 16 - p++,c--,a[r][c]=p
STEP 17 - IF up=1 GOTO STEP 18
STEP 18 - p++,r--,a[r][c]=p
STEP 19 - k1=k1+2, k2=k2+2 & co++
STEP 20 - up++ & IF up<=k2-1 GOTO STEP 18
STEP 21 - le++ & IF le<=k2-1 GOTO STEP 16
STEP 22 - dw++ & IF dw<=k1-1 GOTO STEP 14
STEP 23 - IF y=0 GOTO STEP 24
STEP 24 - IF yy=0 GOTO STEP 25
STEP 25 - PRINT "\t"+a[y][yy]) & ()
STEP 26 - yy++ & IF yy<l GOTO STEP 25
STEP 27 - y++ & IF y<l GOTO STEP 24
STEP 28 – END

solution
import java.io.*;
class SpiralMatrix
{public static void main(String[] args) throws
IOException //main function
{int a[][],r,c,k1=2,k2=3,p=0,co=0,re=0;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the dimension of matrix A x A
=");
int l = Integer.parseInt(br.readLine());
//accepting dimension of square spiral matrix
a=new int[l][l];
r=l/2;c=r-1;
if(l%2==0)
{System.out.println("wrong entry for spiral path");
System.exit(0);
}
/*Calculating and displaying spiral matrix*/
while(p!=(int)Math.pow(l,2))
{if(co!=0)
re=1;
for(int ri=1;ri<=k1-re;ri++)
{p++;c++;if(c==l)break;a[r][c]=p;}
if(c==l)break;
for(int dw=1;dw<=k1-1;dw++)
{p++;r++;a[r][c]=p;}
for(int le=1;le<=k2-1;le++)
{p++;c--;a[r][c]=p;}
for(int up=1;up<=k2-1;up++)
{p++;r--;a[r][c]=p;}
k1=k1+2;
k2=k2+2;
co++;
}
for(int y=0;y<l;y++)
//Displaying matrix
{for(int yy=0;yy<l;yy++)
System.out.print("\t"+a[y][yy]);
System.out.println();
System.out.println();
}}}
output

PROGRAM 9
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 java.io.*;
class MagicSquare
{public static void main(String args[])throws Exception
//main function
{BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the dimension of magical
square=");
int n = Integer.parseInt(br.readLine()); //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;
}
System.out.println();
for(r=0;r<n;r++)
//loop displaying magic square
{for(c=0;c<n;c++)
System.out.print(arr[r][c]+" ");
System.out.println();
}}}
output
PROGRAM 10
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

solution
import java.io.*;
class LinearSearch
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
public LinearSearch(int nn)
{n=nn;
}
public void input() throws IOException
//function for obtaining values from user
{System.out.println("enter elements");
for(i=0;i<n;i++)
{a[i] = Integer.parseInt(br.readLine());
}}
public void display()
//function displaying array values
{System.out.println();
for(i=0;i<n;i++)
{System.out.print(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 )
System.out.println("not found");
else System.out.println(v+" found at position - "+flag);
}
public static void main(String args[]) throws IOException
//main function
{LinearSearch obj = new LinearSearch(10);
obj.input();
obj.display();
System.out.println("enter no. to be searched -");
//accepting the values to be searched
int v = Integer.parseInt(br.readLine());
obj.search(v);
}}

output
PROGRAM 11
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
solution
import java.io.*;
class BinarySearch
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
public BinarySearch(int nn)
//default constructor
{n=nn;
}
public void input() throws IOException
//function accepting array elements
{System.out.println("enter elements");
for(i=0;i<n;i++)
{a[i] = Integer.parseInt(br.readLine());
}}
public void display()
//displaying array elements
{System.out.println();
for(i=0;i<n;i++)
{System.out.print(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 )
System.out.println("not found");
else System.out.println(v+" found at position - "+flag);
}
public static void main(String args[]) throws IOException
//main function
{BinarySearch obj = new BinarySearch(10);
obj.input();
obj.display();
System.out.println("enter no. to be searched -");
int v = Integer.parseInt(br.readLine()); //accepting integer to
be searched by binary search
obj.search(v);
output

PROGRAM 12
To Sort an Srray 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

solution
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();
}}
output

PROGRAM 13
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

solution
import java.io.*;
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(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 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);
x.input();
System.out.print("Before sorting - ");
x.display();
System.out.print("After sorting - ");
x.sort();
x.display();
}}
output

PROGRAM 14
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 java.io.*;
class Dec2Bin
{int n,i;
int a[] = new int[100];
static BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
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;
}
System.out.println("Binary eq. of "+no+" = ");
for( i = c-1 ; i>=0 ; i--)
//Displaying binary number
System.out.print( a[ i ] );
}
public static void mai in(String args[]) throws IOException
//main function
{Dec2Bin obj = new Dec2Bin(30);
D
System.out.println("e enter decimal no -");
int no = Integer.parse eInt(br.readLine());
obj.dectobin(no);
}}

output
PROGRAM 15
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 - sb.reverse
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 java.io.*;
class Palindrome
{public static void main(String args[]) throws IOException
//main function
{BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the string=");
String s = br.readLine();
//accepting the string
StringBuffer sb = new StringBuffer(s);
sb.reverse();
//reversing the string
String rev = new String(sb);
if(s.equalsIgnoreCase(rev))
//checking for palindrome
System.out.println("Palindrome " );
//displaying the result
else System.out.println("Not Palindrome " );
}}

output
PROGRAM 16
To Find a Word in Entered
String

ALGORITHM

STEP 1 - START
STEP 2 - INPUT string s
STEP 3 - StringTokenizer st = s
STEP 4 - l =str.length()
STEP 5 - INPUT look
STEP 6 - flag = -1
STEP 7 - IF (st.hasMoreElements()) REPEAT STEP 8
STEP 8 - IF (look.equals(st.nextElement())) 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 java.util.StringTokenizer;
import java.io.*;
public class WordSearch
{public static void main(String[] args) throws IOException
//main function
{BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the string=");
String s = br.readLine();
//accepting string
StringTokenizer st = new StringTokenizer(s," ");
//StringTokenizer initialization
System.out.println("enter the word to be searched =");
String look = br.readLine();
int flag = -1;
while(st.hasMoreElements())
//searching for word
{if(look.equals(st.nextElement()))
flag =1;
}
if(flag ==-1)
{System.out.println(" "the word not found");
//display ying the result
}
else {
System.out.println("t the word found");
}}}
output

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 = a.length()
STEP 4 - x= 0 , b= 0
STEP 5 - FROM y =0 to y<z REPEAT STEP 6
STEP 6 - IF (a.charAt(y)=='a'||a.charAt(y)=='e'||
a.charAt(y)=='i'||a.charAt(y)=='o'||a.charAt(y)=='u') THEN
x =x +1 OTHERWISE b = b+1
STEP 7 - PRINT x
STEP 8 - PRINT b
STEP 9 – END

solution
import java.io.*;
class Vowels
{public static void main(String args[])throws
IOException //main function
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter a string");
String a= br.readLine();
//Accepting string
int z=a.length(),y,x=0,b=0;
for(y=0;y<z;y++)
//loop for counting number of vowels
{if(a.charAt(y)=='a'||a.charAt(y)=='e'||a.charAt(y)=='i'||
a.charAt(y)=='o'||a.charAt(y)=='u')
x++;
else b++;
}
System.out.println("Number of vowels in string ="+x);
//displaying result
System.out.println("Number of consonants in string ="+b);
}}

output
PROGRAM 18
To Create a String and Count
Number of Words

ALGORITHM
STEP 1 - START
STEP 2 - a = "Computer Applications"
STEP 3 - z = a.length()
STEP 4 - x= 0
STEP 5 - FROM y =0 to y<z REPEAT STEP 6
STEP 6 - IF (a.charAt(y)==' ' ) then x =x+1
STEP 7 - PRINT "Number of words in string ="+(x+1)
STEP 8 – END

solution
import java.io.*;
class NoOfWords
{public static void main(String args[])throws IOException
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter Sentence");
String a=br.readLine();
//accepting string
System.out.println("The string is -"+a);
int z=a.length(),y,x=0;
for(y=0;y<z;y++)
//loop for counting number of spaces
{if(a.charAt(y)==' ')
x=x+1;
}System.out.println("Number of words in string ="+(x+1));
//displaying result
}}

output
PROGRAM 19
To Calculate the Commission
of a Salesman as per the
Following Data :
Sales Commission
>=100000 25% of sales
80000-99999 22.5% of sales
60000-79999 20% of sales
40000-59999 15% of sales
<40000 12.5% of sales

ALGORITHM

STEP 1 - START
STEP 2 - INPUT sales
STEP 3 - IF (sales>=100000) THEN comm=0.25 *sales
OTHERWISE GOTO STEP 4
STEP 4 - IF (sales>=80000) THEN comm=0.225*sales
OTHERWISE GOTO STEP 5
STEP 5 - IF (sales>=60000) THEN comm=0.2 *sales
OTHERWISE GOTO STEP 6
STEP 6 - IF (sales>=40000) THEN comm=0.15 *sales
OTHERWISE GOTO STEP 7
STEP 7 - comm=0.125*sales
STEP 8 - PRINT "Commission of the employee="+comm
STEP 9 – END
solution
import java.io.*;
class SalesComission
{public static void main(String args[])throws IOException
//main function
{double sales,comm;
BufferedReader aa=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(“Enter sales”);
sales=Double.parseDouble(aa.readLine());
//reading sales from the keyboard
/*calculating commis ssion*/
if(sales>=100000)
comm=0.25*sales;
else if(sales>=80000)
comm=0.225*sales;
else if(sales>=60000)
comm=0.2*sales;
else if(sales>=40000)
comm=0.15*sales;
else comm=0.125*sa les;
System.out.println("C
Commission of the employee="+comm); //d
displaying commission
}}
output

PROGRAM 20
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 java.io.*;
class C2F
{ public static void main(String args[])throws IOException
//main function
{Temperature ob= new Temperature();
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter temperature in Celsius");
//accepting temperature
double
temp=ob.convert(Double.parseDouble(br.readLine()));
System.out.println("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;
}}
output

You might also like