0% found this document useful (0 votes)
438 views48 pages

Isc Computer Science Project

This document contains details of a computer science project for the 2016-2017 school year at The Assembly of God Church School. It includes 15 programming problems covering topics like number handling, arrays, object handling, inheritance, recursion, linked lists, string processing, and more. For each problem, it provides the problem statement, algorithm, sample code solution, and description of key variables and methods used in the solution. The document aims to provide students with practice on core programming concepts through a variety of short programming exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
438 views48 pages

Isc Computer Science Project

This document contains details of a computer science project for the 2016-2017 school year at The Assembly of God Church School. It includes 15 programming problems covering topics like number handling, arrays, object handling, inheritance, recursion, linked lists, string processing, and more. For each problem, it provides the problem statement, algorithm, sample code solution, and description of key variables and methods used in the solution. The document aims to provide students with practice on core programming concepts through a variety of short programming exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

ISC COMPUTER

SCIENCE PROJECT
2016-2017

THE ASSEMBLY OF GOD


CHURCH SCHOOL
XII ISC COMPUTER PROJECT

ISC PROJECT 2016-2017 AGCS

SL
NO.
1

PAGE
NO.

CONTENT
Number Handling: WAP to Check
Whether a Number is Smith or Not.
1 Dimensional Array: WAP to Perform
Linear Search.
2 Dimensional Array: WAP to Print
Spiral Matrix.
Object Handling: To Display the Entered
String
in Alphabetical Order
Array of Objects: WAP to To Display
Date From Entered Day Number.

Inheritance: WAP to Print Calender of


Any Month.

Recursion: WAP to Print Fibonacci


Series .

8
9
10

Link List: Sum of All Matrix Elements


Link List: Sum of Matrix Column
Elements
Link List: Sum of Matrix Diagonal
Elements

11

WAP to Perform Decode Of a String.

12

WAP to Print Star Pattern Using Input String.

13

WAP to Print Frequency of Each String


Character.

14

WAP to Calculate Sales Commission.

15

WAP to Perform Decimal to Roman Numerical.


*END*

ISC PROJECT 2016-2017 AGCS

WAP to Check Smith Number.


Algorithm.

Output:
1. Enter a Number : 94
Sum of Digit = 13
Sum of Prime Factor = 13
It is a Smith Number
2. Enter a Number : 102
Sum of Digit = 3
Sum of Prime Factor = 13
It is Not a Smith Number
3. Enter a Number : 4937775
Sum of Digit = 42
Sum of Prime Factor = 42
It is a Smith Number
ISC PROJECT 2016-2017 AGCS

Program Code:
import java.io.*;
class Smith
{
static BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
//function for finding sum of digits
int sumDig(int n)
{
int s=0;
while(n>0)
{
s=s+n%10;
n=n/10;
}
return s;
}
//function for generating prime factors and finding their sum
int sumPrimeFact(int n)
{
int i=2, sum=0;
while(n>1)
{
if(n%i==0)
{
sum=sum+sumDig(i); //Here 'i' is the prime factor of 'n' and we
are finding its sum
n=n/i;
}
else
i++;
}
return sum;
}
public static void main(String args[]) throws IOException
ISC PROJECT 2016-2017 AGCS

{
Smith ob=new Smith();
System.out.print("Enter a Number : ");
int n=Integer.parseInt(br.readLine());
int a=ob.sumDig(n);// finding sum of digit
int b=ob.sumPrimeFact(n); //finding sum of prime factors
System.out.println("Sum of Digit = "+a);
System.out.println("Sum of Prime Factor = "+b);
if(a==b)
System.out.print("It is a Smith Number");
else
System.out.print("It is Not a Smith Number");
}}

PROGRAM 2
To Search an Array Using
Linear Search

ALGORITHM
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
10
STEP
STEP
STEP

1
2
3
4
5
6
7
8

START
INPUT a[]
FROM i=0 to i<n REPEAT STEP 4
PRINT a[i]+" "
flag=-1
FROM i=0 to i<n REPEAT
IF (a[i] == v) THEN flag =i
IF (flag=-1) THEN GOTO STEP 9 OTHERWISE GOTO STEP

9 - PRINT not found


10 - PRINT v+" found at position - "+flag
11 END
ISC PROJECT 2016-2017 AGCS

ISC PROJECT 2016-2017 AGCS

Solution:
import
java.io.*;
class
LinearSearc
h {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
//function for obtaining values
IOException
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
//linear search
search(int v)
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 -");
int v =
Integer.parseInt(br.readLine())
;
obj.search(v);
}}

//accepting the values to


be searched

Variable description
1
2
3
4

Nam
e
Type
Buffere
br
dReader
n
int
i
int
a[]
int[]

nn

6
7
8

v
flag
obj

No.

Method

LinearSearch(
int
)
search(),
int
main()
int
search()
LinearS earch main()

Output:

Description
BufferedReader o bject
array length
loop variable
input array
parameter in constructor
search element
flag
LinearSearch obje ct

PROGRAM
3

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
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP

19
20
21
22
23
24
25
26
27
28

- k1=k1+2, k2=k2+2 & co++


- up++ & IF up<=k2-1 GOTO STEP 18
- le++ & IF le<=k2-1 GOTO STEP 16
- dw++ & IF dw<=k1-1 GOTO STEP 14
- IF y=0 GOTO STEP 24
- IF yy=0 GOTO STEP 25
- PRINT "\t"+a[y][yy]) & ()
- yy++ & IF yy<l GOTO STEP 25
- y++ & IF y<l GOTO STEP 24
END

Solution
import
java.io.*;
class
SpiralMatri
x
{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();

}}}

Variable description
No.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Nam
e
Type
Buffere
br
dReader
a
int[][]
r
int
c
int
k1
int
k2
int
p
int
co
int
re
int
l
int
ri
int
le
int
dw
int
up
int
y
int
yy
int

Output:

Metho
d
Description
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()
main()

BufferedReader object
spiral matrix
l/2
r-1
stores 2
stores 3
loop gate
coloumn index
row index
dimensions of thr matrix
right side matrix loop varia ble
left side matrix loop variab le
down side matrix loop vari able
up side matrix loop variable
loop variable to print matrix
loop variable to print matrix

PROGRAM 4
To Display the Entered String
in Alphabetical Order

ALGORITHM
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP
STEP

1 - START
2 - str = "" , l = 0
3 - INPUT string str
4 - l =str.length()
5 - FROM i=0 to i<l REPEAT STEP 6
6 - c[i] = str.charAt(i)
7 - FROM i=0 to i<l-1 REPEAT STEP 8
8 - FROM j=0 to i<l-1 REPEAT STEP 9
9 - temp =c[j], c[j] = c[j+1] , c[j+1] = temp
10 - FROM i=0 to i<l REPEAT STEP 11
11 - PRINT c[i]
12 END

Solution:
import java.io.*;
class Alpha
{String str;
int l;
char c[] = new char[100];
//Alpha()
constructor

public Alpha()
{str = "";
l =0;
}
public void readword() throws
//function to read input
IOException
string
{System.out.println("ente
r word - ");
BufferedReader br =new BufferedReader(new
InputStreamReader(System.in));
str = br.readLine();
l = str.length();
}
//function to arrange string in
public void arrange()
ascending order
{int i,j;
char temp;
for(i=0;i<l;i++)
{c[i]= str.charAt(i);
}
//loops for swapping of
for(i=0;i<l-1;i++)
characters
{for(j=0;j<l-1-i;j++)
{if(c[j] > c[j+1])
{temp = c[j];
c[j] = c[j+1];
c[j+1] = temp;
}}}}
//function to display the
public void display()
rearranged string
{System.out.println();
for(int i=0;i<l;i++)
{System.out.print(c[i]);
}}
public static void main(String args[])
//main
throws IOException
function

{Alpha obj = new Alpha();


obj.readword();
obj.arrange();
obj.display();
}}

Variable description:
Nam
Type
No. e
BufferedRead
1
br
er
2
str
String
3
l
int
4
c
char[]
5

int

int

7
8

temp char
obj
Alpha

Output:

Method
readword(
)
readword(
)
readword(
)
readword(
)
main()

Description
BufferedReader object
input string
length
character array
loop variable
loop variable
temporary storage
Alpha object

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

Solution:
import
java.io.*;
class
Day2Date
{static BufferedReader br =new BufferedReader(new
InputStreamReader(System.in)); 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;
//loop calculating
while( t < n)
date
{t =t + a[s++];
}
int d = n + a[--s] t;
if( d == 1|| d == 21 || d == 31 )
{System.out.println( d + "st" +
m[s] + " , "+yr);
}
if( d == 2 || d ==
22 )
{System.out.println( d + "nd" +
m[s] + " , "+yr);
}
if( d == 3|| d ==
23 )
{System.out.println( d + "rd" +
m[s] + " , "+yr);
}
else {System.out.println( d + "th" + m[s]
+ " , "+yr);
}}
public static void main(String args[])
//main
throws IOException
function

{Day2Date obj = new


Day2Date();
System.out.println( "Enter day no
= ");
//accepting day no.
int n =
Integer.parseInt(br.readLine());
System.out.println( "Enter year =
");
//accepting year
int yr =
Integer.parseInt(br.readLine());
obj.calc(n,yr);
}}

Variable description:
1

Nam
e
Type
Buffere
br
dReader

int

3
4
5
6
7
8
9

yr
a
m
t
s
d
obj

int
int[]
int[]
int
int
int
Day2D ate

No.

Output:

Method

Description

calc(),
main()
calc(),
main()
calc()
calc()
calc()
calc()
calc()
main()

BufferedReader obje ct
Day number
year
array storing day
array storing month
array index
array index
n+a[--s]+t
Day2Date object

PROGRAM 6
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","Novembe
r","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.charA

t(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<mont
h;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.print
ln(" ");
}}}

Variable description:
No.

1
2
3
4
5
6
7
8
9
10

Name Type
BufferedRead
br
er
i
int
count int
b
int
d
int
month int
year
int
w
Strin g
days
Strin g[]
month
1
Strin g[]

Metho
d
Description
dee()
dee()
dee()
dee()
dee()
dee()
dee()
dee()
dee()

BufferedReader object
loop variable
counter
week counter
day counter
input month
input year
week days
array storing days

dee()

array storing months

Output:

PROGRAM 7
To Display Fibonacci Series
Using Recursion

ALGORITHM

STEP 1 STEP 2 STEP 3 (fib(n-1)

START
INPUT n
IF(n<=1) THEN return 1 OTHERWISE return
+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));
}}

Variable description:
No.

1
2
3
4
5

Nam
e
Type
Buffere
br
dReader
obj
Fibona cci
n
int
i
int
f
int

Metho
d
Description
main()
main()
main()
main()
main()

BufferedReader object
Fibonacci object
input number
loop variable for Fibonacci element
Fibonacci element

int

fib()

recursive function fib() par ameter

Output:

PROGRAM 8
To Generate Sum of All
Elements of a Double
Dimensional Array of 5*5

Subscripts
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM x =0 to x<5 REPEAT
STEP 4 - FROM y =0 to y<5 REPEAT
STEP 5 - PRINT (a[x][y]+" "
STEP 6 - FROM x =0 to x<5 REPEAT
STEP 7 - FROM y =0 to y<5 REPEAT
STEP 8 - Sum=Sum+a[x][y]
STEP 9 - PRINT Sum
STEP10 END

STEP 4
STEP 5
STEP 7
STEP 8

Output:

Solution
import java.io.*;
class MatrixSum
{public static void main(String args[])throws IOException //main
function
{ int a[][]=new int[5][5];
BufferedReader aa=new BufferedReader(new
InputStreamReader(System.in));
int
x,y,z,Sum=0;
System.out.println("Enter

the array");
for(x=0;x<5;x+
+)
//loop for reading array
{for(y=0;y<5;y
++)
{ z=Integer.parseInt(aa.read
//accepting array
Line());
element
a[x][y]=z;
}}
System.out.println(" Array -");
for(x=0;x<5;x++)
//loop for printing array
{for(y=0;y<5;y++)
{System.out.print(a[x ][y]+" ");
}
System.out.print("\n");
}
for(x=0;x<5;x++)
//loop for printing sum of array el ements
{for(y=0;y<5;y++)
{Sum=Sum+a[x][y];
}}
System.out.println(" Sum of Array elements="+Sum);
//displaying sum
}}

Variable description:
No.

1
2
3
4
5
6

Nam
e
Type
Buffere
aa
dReader
a
int[][]
x
int
y
int
z
int
Sum main()

Metho
d
Description
main()
main()
main()
main()
main()
main()

BufferedReader object
input array
loop variable
loop variable
input element
Sum of all elements

PROGRAM 9

To Find Sum of Each Column


of a Double Dimensional
Array
ALGORITHM
STEP 1 - START
STEP 2 - INPUT a[]
STEP 3 - FROM x =0 to x<4 REPEAT
STEP 4 - FROM y =0 to y<4 REPEAT
STEP 5 - PRINT (a[x][y]+" "
STEP 6 - FROM x =0 to x<4 REPEAT
STEP 7 - FROM y =0 to y<4 REPEAT
STEP 8 - Sum=Sum+a[x][y] ,
STEP 9 - PRINT Sum
STEP 10 - Sum
= 0 STEP11
END

Solution:

STEP 4
STEP 5
STEP 7 , STEP 9 and STEP 10
STEP 8

import java.io.*;
class ColoumnSum
{public static void main(String args[])throws IOException //main
function
{int a[][]=new int[4][4];
BufferedReader aa=new BufferedReader(new
InputStreamReader(System.in));
int x,y,z,Sum=0;
System.out.println("Enter the array");
//reading array
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}

System.out.println(" Array
//printing the arra y in matrix
-");
form
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{System.out.print(a[x ][y]
+" ");
}System.out.print("\n ");
}
for(y=0;y<4;y++)
{for(x=0;x<4;x++)
{Sum=Sum+a[x][y];
}
System.out.println(" Sum of column "+
//printing sum of
(y+1)+" is "+Sum);
coloumn
Sum=0;
}}}

Variable description:
No.

1
2
3
4
5
6

Nam
e
Type
Buffere
aa
dReader
a
int[][]
x
int
y
int
z
int
Sum int

Output:

Metho
d
Description
main()
main()
main()
main()
main()
main()

BufferedReader object
input array
loop variable
loop variable
input element
Sum of each couloumn

PROGRAM
10

To Find Sum of Diagonal of


a Double Dimensional Array
of 4*4 Subscripts

ALGORITHM
STEP 1- START
STEP 2- INPUT a[]
STEP 3- FROM x =0 to x<4 REPEAT STEP 4
STEP 4- FROM y =0 to y<4 REPEAT STEP 5
STEP 5- PRINT (a[x][y]+" "
STEP 6- FROM x =0 to x<4 REPEAT STEP 7
STEP 7 - Sum=Sum+a[x][y] , y=y+1
STEP 9- PRINT Sum
STEP 10 - Sum = 0
STEP11- END

Output:

Solution:
import java.io.*;
class DiagonalSum
{public static void main(String args[])throws IOException //main
function
{int a[][]=new int[4][4];
BufferedReader aa=new BufferedReader(new
InputStreamReader(System.in));
int x,y,z,Sum=0;
System.out.println("Enter the array");
for(x=0;x<4;x++) //Reading array
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}
System.out.println("Array -");
for(x=0;x<4;x++)
//displaying array
{for(y=0;y<4;y++)
{System.out.print(a[x ][y]+" ");
}
System.out.print("\n");
}
y=0;
for(x=0;x<4;x++)
//loop for finding sum of diagonal
{Sum=Sum+a[x][y];
y=y+1;
}
System.out.println(" Sum of diagonal is "+Sum);
//displaying
the sum of diagonal
Sum=0;

}}

Variable description:
No.

1
2
3
4
5
6

Nam
e
Type
Buffere
aa
dReader
a
int[][]
x
int
y
int
Sum int
z
int

Metho
d
Description
main()
main()
main()
main()
main()
main()

BufferedReader object
input matrix
loop variable
loop variable
Sum of diagonals
input element

PROGRAM
11

To Decode the Entered String


ALGORITHM
STEP 1 - START
STEP 2 - INPUT
name, n STEP 3 l=name.length()
STEP 4 - PRINT original string is "+name

STEP 5 - IF i=0 THEN GOTO STEP 6


STEP 6 - char
c1=name.charAt(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=Math.abs(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 java.io.*;
class Decode
{public void compute()throws IOException
//compute()
function
{BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(Enter name:);
String name=br.readLine();
System.out.println(Enter
number:); int
n=Integer.parseInt(br.readLi
ne()); int j,i,l,c=0,y,n1;

l=name.length();
System.out.println("original string is "+name);
for(i=0;i<l;i++)
{char c1=name.charAt(i);

try
//trying for NumberFormatException
{c=(int)c1 ;
}
catch(NumberFormatEx
ception e) {}
if(n>0)
{if((c+n)<=90
)
/*Decoding
String*/
System.out.print((ch
ar)(c+n)); else
{c=c+n;
c=c
%10;
c=65+
(c-1);
System.out.print((char)(c));
}}
else if(n<0)
{n1=Math.ab
s(n); if((c-n1)
>=65)

System.out.print((cha
r) (c-n1)); else
{if(c>65)
c=c65;
else
c=n1;
System.out.print((char)(90-(c-1)));
}}
else if (n==0)
{System.out.println("no
change "+name); break;
}}}}

Variable description:
No.

Nam
e
Type

1
2

br
Buffere dReader
name String

Method Description
compute(
)
BufferedReade r object
compute( input string

int

int

int

int

int

int

n1

int

10

c1

11

char
Numbe
rFormatException

Output:

)
compute(
)
compute(
)
compute(
)
compute(
)
compute(
)
compute(
)
compute(
)
compute(
)
compute(
)

decode numbe r
loop variable
loop variable
length of string
ASCII of c1

character at index i
NumberFOrma tException object

PROGRAM
12

To Create a Star Pattern


From Entered String

Solution:
import
java.io.*;
class
Pattern
{public static void main (String args[])
throws IOException {int i,sp,j,k,l;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter the string ="); //accepting
string
String s =
br.readLine();
l=s.length();
/*printing the
pattern*/
for(i=0;i<l;i++)
if(i==l/2)
System.out.println
(s); else
{sp=Math.abs((l/2
)-i);
for(j=sp;j<l/2;j++)
System.out.print("
"); k=0;
while(k<3)
{System.out.print(s.

charAt(i));
for(j=0;j<sp-1;j++)
System.out.print("
");
k++;
}
System.out.println(" ");
}}}

Variable description:
No.

1
2
3
4
5
6
7

Nam
e
Type
Buffere
br
dReader
s
String
i
int
sp
int
j
int
k
int
l
int

Output:

Metho
d
Description
main()
main()
main()
main()
main()
main()
main()

BufferedReader object
input string
loop variable for printing the pattern
Math.abs((l/2)-i)
loop variable for printing the pattern
loop variable for printing the pattern
length of string

PROGRAM
13

To Display a Frequency of
Each Character in Entered
String

ALGORITHM
STEP 1 - START
STEP 2 - INPUT str
STEP 3 - l=str.length()
STEP 4 - PRINT str
STEP 5 - IF i=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 6 - char a=str.charAt(i)
STEP 7 - IF ii=0 THEN GOTO STEP 4 OTHERWISE GOTO STEP 22
STEP 8 - char b = str.charAt(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

Solution:
import java.io.*;
class Frequency
{private int
i,a1,l,p,j,freq;
//default
constructor

public Frequency()
{p=0;
freq=0;
// initialise instance variables
}
public void
count(String str)
//counting character frquency
{int ii;
l=str.leng
th();
System.out.print(str);
for(i=0;i<
l;i++)
{char a=str.charAt(i);
for(ii=0;ii<l;ii++)
{char b =
str.charAt(ii);
if (a==b)
freq=freq
+1;
}
System.out.println(a+" occurs "+freq+"
//displaying
times");
frequency
freq=0;
}}
public static void main(String args[])
//main
throws IOException
function
{BufferedReader br =new BufferedReader(new

InputStreamReader(System.in));
System.out.println("enter string");
String str =
br.readLine();
Frequency x = new
Frequency();
x.count(str);
}}

Variable description:
No.

1
2
3
4
5
6
7
8
9
10
11

Nam
e
Type
Buffere
br
dReader
i
int
a1
int
l
int
p
int
freq int
ii
int
a
char
b
char
str
String
x
Frequency

Output:

Metho
d
Description
main()
count()
count()
count()
main()
main()

BufferedReader object
loop variable
instance variable
length of string
instance variable
frequency of characters
loop variable
character at index i
character at index ii
input string
Frequency object

PROGRAM
14

To Calculate the Commission


of a Salesman as per the
Following Data

Sales Commission:
>=100000 25%
of sales 8000099999 22.5% of
sales 6000079999 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
//main
args[])throws IOException
function
{double sales,comm;
BufferedReader aa=new BufferedReader(new
InputStreamReader(System.in));
System.out.println(Enter
sales);
sales=Double.parseDouble(aa.r
//reading sales from the
eadLine());
keyboard
if(sales>=100000)
comm=0.25*sales;
else
if(sales>=8000
0)
comm=0.225*s
ales; else

if(sales>=6000
0)
comm=0.2*sal
es; else
if(sales>=4000
0)
comm=0.15*sa
les;
else comm=0.125*sales;
System.out.println(" Commission of the employee="+comm); //
displaying commission
}}

Variable Description:
1

Metho
Name Type
d
Description
BufferedRead
aa
er
main() BufferedReader object

sales

comm
.
doubl e

No.

doubl e

main() sales

main() commision

Output:

PROGRAM
15
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 java.io.*;
public class Dec2Roman
{public static void main() throws IOException //main function
{DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter Number : ");

int num=Integer.parseInt(in.readLine()); //accepting decimal


number
String
hund[]={"","C","CC","CCC","CD","D","DC","DCC","
DCCC","CM"}; String
ten[]={"","X","XX","XXX","XL","L","LX","LXX","LX
XX","XC"}; String
unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"
}; /*Displaying equivalent roman number*/
System.out.println("Roman Equivalent=
"+hund[num/100]+ten[(num/10)%10]+unit[num%10]);

}}

Variable description:
No.

1
2
3
4
5

Nam
e
Type
DataIn
in
putStream
num int
hund String[]
ten
String[]
unit
String[]

Output:

Metho
d
Description
main()
main()
main()
main()
main()

DataInputStream object
input number
array storing 100th positi on
array storing 10th positio n
array storing units positio n

Teachers Signature:

Remarks:

Invigilators Signature:

Remarks:

*The End*

You might also like