1. (
(1
1)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
an
ny
y s
st
tr
ri
in
ng
g a
an
nd
d p
pr
ri
in
nt
t t
th
he
e f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f e
ea
ac
ch
h c
ch
ha
ar
ra
ac
ct
te
er
r
w
wi
it
th
hi
in
n t
th
he
e s
st
tr
ri
in
ng
g.
. T
Th
he
e c
ch
ha
ar
ra
ac
ct
te
er
rs
s w
wi
it
th
h m
mu
ul
lt
ti
ip
pl
le
e f
fr
re
eq
qu
ue
en
nc
ci
ie
es
s s
sh
ho
ou
ul
ld
d b
be
e d
di
is
sp
pl
la
ay
ye
ed
d o
on
nl
ly
y
o
on
nc
ce
e.
.
Algorithm-
Step1 Start.
Step2 Declare suitable variables like n,i,jand str variable of string type.
Step3 Start a loop from i=65 to i<=90.
Step4 Start a loop from j=0 to j<=length of string.
Step5 Check if int(ch)==i and if true then increment p by 1 and then print
the value of p.
Step6 Repeat step3 and step4 with i=97 and i<= 122 and then repeat
step5.
2. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
2
Step7 End.
Variable Discription :
* TYPE NAME PURPOSE
* int n Store length of str1
* String str1 to add character.
* Int i looping variable
* Int j looping variable
* Int p counter variable
* char ch to store present character
* char ch2 to compare with ch2
PROGRAM-
import java.io.*;
class frequencyofeachletter // defining class
{
public static void main(String args[])throws Exception //defining main function
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
String str,str1=new String();//declaring string
str1=" ";
int n,i,j,p=0;
System.out.println("Enter your string");
str=num.readLine(); //accepting data from the user
n=str.length();
for(i=65;i<=90;i++) //generating loop
{
for(j=0;j<n;j++) //generating loop
{
char ch=str.charAt(j); // extracting a character
if((int)ch==i)
{
p++;
}
}
char ch2=(char)i;
System.out.print("frequency of "+ch2+"= "+" "+" "); //printing
System.out.print(p+" ");
System.out.println();
p=0;
}
for(i=97;i<=122;i++)// generating loop
{
for(j=0;j<n;j++)
{
char ch=str.charAt(j);
3. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
3
if((int)ch==i)
{
p++;
}
}
char ch2=(char)i;
System.out.print("frequency of "+ch2+"= "+" "+" ");//printing
System.out.print(p+" ");
System.out.println();
p=0;
}
}
}
o
ou
ut
tp
pu
ut
t-
-
I
IN
NP
PU
UT
T—
—
F
FI
IS
SS
SI
IO
ON
N O
OC
CC
CU
UR
RS
S W
WH
HE
EN
N O
ON
NE
E E
EL
LE
EM
ME
EN
NT
T B
BR
RE
EA
AK
KS
S I
IN
NT
TO
O S
SE
EV
VE
ER
RA
AL
LO
OT
TH
HE
ER
RS
S,
,R
RE
EL
LE
EA
AS
SI
IN
NG
G
E
EN
NE
ER
RG
GY
Y I
IN
N P
PR
RO
OC
CE
ES
SS
S.
.
O
OU
UT
TP
PU
UT
T—
—
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f H
H=
= 2
2
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f I
I=
= 5
5
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f J
J=
= 0
0
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f K
K=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f L
L=
= 3
3
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f M
M=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f N
N=
= 8
8
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f O
O=
= 6
6
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f P
P=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f Q
Q=
= 0
0
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f R
R=
= 7
7
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f S
S=
= 9
9
4. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
4
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f T
T=
= 3
3
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f U
U=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f V
V=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f W
W=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f X
X=
= 0
0
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f Y
Y=
= 1
1
f
fr
re
eq
qu
ue
en
nc
cy
y o
of
f Z
Z=
= 0
0
(
(2
2)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t t
th
hr
re
ee
e b
bi
in
na
ar
ry
y n
nu
um
mb
be
er
rs
s a
an
nd
d d
di
is
sp
pl
la
ay
y t
th
he
e s
su
um
m o
of
f t
th
he
em
m.
.
F
Fo
or
r e
eg
g-
-
1
11
10
01
1+
+1
10
00
01
1+
+1
11
10
00
0=
=1
10
00
00
01
10
0.
.
Algorithm-
Step1. Initialize array arr [] with 100.
Step 2. Declare a,b,c,i,s,s1,s2,d,d1,d2,c,c0,c1,c2,sum,k.
Step 3. Initilize s,s1,s2,d,d1,d2,sum,k with 0 and c0,c1,c2 with 1;
Step 4. Input three binary number from user.
5. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
5
Step 5. Begin loop for i from a to1 and repeat step 6 to 8.
Step 6. Assign value of i%10 to s.
Step 7. d=d+s*c0.
Step 8. Assign value of c0*2 to c0.
Step 9. Begin loop for i from b to1 and repeat step 10 to 12.
Step 10. Assign value of i%10 to s1.
Step 11. d1=d1+s1*c1.
Step 12. Assign value of c1*2 to c1.
Step 13. Begin loop for i from c to1and repeat step 14 to 16.
Step 14. Assign value of i%10 to s2.
Step 15. d2=d2+s2*c2.
Step 16. Assign value of c2*2 to c2.
Step 17. Add d,d1,d2 and store the value to sum.
Step 18 Begin while loop for sum upto 0 and repeat step 19 to 21.
Step 19. Assign value of sum%2 to sum.
Step 20. Assign value of sum/2 to sum.
Step 21. k++.
Variable Discription :
TYPE NAME PURPOSE
int c To get the remainder
Int i looping variable
Int n1,n2,n3 To store 3 nos. by user
Int sum1,sum2,sum3 To get the sum of binary nos.
int p1,p2,p3 to store powers
int k array variable
int sum4 sum of all 3 nos.
int a[] array
PROGRAM-
import java.io.*;
class Sum_Binary // class begins
{
public static void main()throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int c,i,n1,n2,n3,sum1=0,sum2=0,sum3=0,p1=0,p2=0,p3=0,p,k=0,sum4;
// initializing variables.
int a[]=new int[10];
System.out.println("Enter three numbers"); // get input by user
n1=Integer.parseInt(num.readLine());
n2=Integer.parseInt(num.readLine());
6. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
6
n3=Integer.parseInt(num.readLine());
for(i=n1;i>0;i/=10) // for loop for first number
{
c=i%10;
sum1=sum1+(int)Math.pow(2,p1)*c;
p1++;
}
for(i=n2;i>0;i/=10) // for loop foe second number
{
c=i%10;
sum2=sum2+(int)(Math.pow(2,p2)*c);
p2++;
}
for(i=n3;i>0;i/=10) // for loop for third number
{
c=i%10;
sum3=sum3+(int)(Math.pow(2,p3)*c);
p3++;
}
sum4=sum1+sum2+sum3; // sum of all three numbers
System.out.print(sum4);
while(sum4>0)
{
p=sum4%2;
a[k]=p;
k++;
sum4=sum4/2;
}
System.out.println("The added binary number is = "); // printing comment
for(i=k-1;i>=0;i--)
{
System.out.print(a[i]);
}
}
} // class ends
output-
I
In
np
pu
ut
t—
—
E
En
nt
te
er
r t
th
hr
re
ee
e n
nu
um
mb
be
er
rs
s
1
10
00
01
1
1
11
10
01
1
1
11
10
00
0
O
Ou
ut
tp
pu
ut
t-
--
-
t
th
he
e a
ad
dd
de
ed
d b
bi
in
na
ar
ry
y n
nu
um
mb
be
er
r i
is
s=
=1
10
00
00
01
10
0.
.
7. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
7
(
(3
3)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
a n
nu
um
mb
be
er
r a
an
nd
d d
di
is
sp
pl
la
ay
y t
th
he
e f
fo
ol
ll
lo
ow
wi
in
ng
g p
pa
at
tt
te
er
rn
n.
.
N
N=
=4
4
1
1 8
8 1
13
3 1
16
6
5
5 2
2 9
9 1
14
4
1
11
1 6
6 3
3 1
10
0
1
15
5 1
12
2 7
7 4
4
Algorithm-
1).Declare a matrix a[][] of size 10.
2).Declare variable r,c,n and initialize n with 4.
3).Begin loop for r from 0 to 3 and repeat step 4.
4).Assign r+1 to a[r][r].
5).Begin loop for r from 0 to 2 and repeat step 6.
6).Assign n+1 to a[r+1][r],n+4 to a[r][r+1] and n+1 to n.
7).Begin loop for r from 0 to 1 and repeat step 8.
8).Assign n+4 to a[r+2][r],n+6 to a[r][r+2] and n+1 to n.
9). Begin loop for r from 3 to less than 1 and repeat step 10 and 11.
10).Begin loop for c from 0 to less than 1 and repeat step 11.
11).Assign n+6 to a[r][c] and n+7 to a[c][r].
12).Print a[][] for 4 rows and 4 columns.
Variable Discription :
TYPE NAME PURPOSE
int a[][] Store 2-D array.
int c1,c2 counter variable
Int i looping variable
Int n input by user
Int r row of 2-D array
int c column of 2-D array
PROGRAM-
8. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
8
import java.io.*;
class matrix // class begins
{
public static void main()throws Exception // defining main function
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[20][20]; // declaring matrix
int p=1,c1=0,c2=0,k1=1,k=1,r,c,n,i;
System.out.println("enter your limit");
n=Integer.parseInt(num.readLine()); // accepting values by the user
for(r=0;r<n;r++) // loop generated
{
for(c=0;c<n;c++) // inner loop
{
if(r==c) // conditional statement
{
a[r][c]=p++;
}
}
}
for(i=1;i<n;i++) // loop generated
{
for(r=k;r<n;r++) // inner loop
{
a[r][c1]=p++;
c1++;
}
k++;
c1=0;
for(r=k1;r<n;r++) // loop generated
{
a[c2][r]=p++;
c2++;
}
k1++;
c2=0;
}
for(r=0;r<n;r++) // loop generated
{
for(c=0;c<n;c++) // inner loop
{
System.out.print(a[r][c]+" "); // printing of matrix
}
System.out.println();
}
}
} // class ends
9. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
9
o
ou
ut
tp
pu
ut
t-
-
I
In
np
pu
ut
t-
--
-
e
en
nt
te
er
r y
yo
ou
ur
r l
li
im
mi
it
t
5
5
O
Ou
ut
tp
pu
ut
t-
--
-
1
1 1
10
0 1
17
7 2
22
2 2
25
5
6
6 2
2 1
11
1 1
18
8 2
23
3
1
14
4 7
7 3
3 1
12
2 1
19
9
2
20
0 1
15
5 8
8 4
4 1
13
3
2
24
4 2
21
1 1
16
6 9
9 5
5
4
4)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o g
ge
en
ne
er
ra
at
te
e a
a m
ma
ag
gi
ic
ca
al
l m
ma
at
tr
ri
ix
x.
.A
A m
ma
ag
gi
ic
ca
al
l m
ma
at
tr
ri
ix
x i
is
s s
su
uc
ch
h t
th
ha
at
t t
th
he
e s
su
um
m o
of
f e
ea
ac
ch
h r
ro
ow
w,
,e
ea
ac
ch
h c
co
ol
lu
um
mn
n
n
nd
d e
ea
ac
ch
h d
di
ia
ag
go
on
na
al
l i
is
s a
al
lw
wa
ay
ys
s s
sa
am
me
e.
.
Eg.
8+1+6
3+5+7
4+9+2
Algorithm-
Step1 Start.
Step2 Declare suitable variables like n,r=0,I,r1,c1,c and declare an 2-d array of limit 10.
Step3 Take an odd limit in n and perform c=n/2.
Step4 Start a loop from i=1 to i<=n*n.
Step5 Strore a[r][c] in I and then put r1=r,c1=c.
Step6 Perform r-- and c++.
Step7 Check if r==-1 then put r=n-1.
Step8 Check if r>n-1 then put r=0.
Step9 Check if c>n-1 then put c=0.
Step10 Check if a[r][c]!=0,if so then put r=r1,c=c1,r++.
Step11 Now print the elements of 2-d array.
Step12 End.
10. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
10
Variable Discription :
* TYPE NAME PURPOSE
* int a[][] Store 2-D array.
* int i looping variable
* int n input by user
* int r row of 2-D array
* int c column of 2-D array
PROGRAM-
import java.io.*;
class magic // defining class
{
public static void main(String args[])throws Exception
{ // defining main function
BufferedReader num=new BufferedReader
(new InputStreamReader(System.in));
int a[][]=new int[10][10]; // declaring array
int n,r=0,i,r1,c1,c;
System.out.println("Enter your odd limit");
n=Integer.parseInt(num.readLine()); // taking input from the user
c=n/2;
for(i=1;i<=n*n;i++) // for loop
{
a[r][c]=i;
r1=r;
c1=c;
r--;
c++;
if(r==-1) // conditional statement
{
r=n-1;
}
if(r>n-1) // conditional statement
{
r=0;
}
if(c>n-1) // conditional statement
{
c=0;
11. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
11
}
if(a[r][c]!=0) // conditional statement
{
r=r1;
c=c1;
r++;
}
}
for(r=0;r<n;r++) // for loop
{
for(c=0;c<n;c++)// inner for loop
{
System.out.print(a[r][c]); // printing of array
}
System.out.println();
}
} // main function ends
} // class ends
o
ou
ut
tp
pu
ut
t-
-
I
In
np
pu
ut
t-
--
-
E
En
nt
te
er
r y
yo
ou
ur
r o
od
dd
d l
li
im
mi
it
t
3
3
O
Ou
ut
tp
pu
ut
t-
-
8
8 1
1 6
6
3
3 5
5 7
7
4
4 9
9 2
2
12. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
12
(
(5
5)
) A
A s
sq
qu
ua
ar
re
e o
of
f s
sq
qu
ua
ar
re
e m
ma
at
tr
ri
ix
x c
ca
an
n b
be
e g
ge
en
ne
er
ra
at
te
ed
d b
by
y t
ta
ak
ki
in
ng
g a
an
ny
y s
sq
qu
ua
ar
re
e m
ma
at
tr
ri
ix
x o
of
f e
ev
ve
en
n d
di
im
me
en
ns
si
io
on
ns
s (
(>
>=
=2
2)
)
a
an
nd
d f
fi
il
ll
l t
th
he
e i
in
nn
ne
er
rm
mo
os
st
t n
nu
um
mb
be
er
r n
n i
is
s c
ci
ir
rc
cu
ul
la
ar
r o
or
rd
de
er
r.
. T
Th
he
en
n f
fi
il
ll
l i
it
ts
s s
su
ur
rr
ro
ou
un
nd
di
in
ng
g s
sq
qu
ua
ar
re
e o
on
ne
e b
by
y o
on
ne
e.
.
E
Eg
g N
N=
=4
4 s
si
iz
ze
e=
=6
6
2
20
0 2
21
1 2
22
2 2
23
3 2
24
4 2
25
5
3
39
9 8
8 9
9 1
10
0 1
11
1 2
26
6
3
38
8 1
19
9 4
4 5
5 1
12
2 2
27
7
3
37
7 1
18
8 7
7 6
6 1
13
3 2
28
8
3
36
6 1
17
7 1
16
6 1
15
5 1
14
4 2
29
9
3
35
5 3
34
4 3
33
3 3
32
2 3
31
1 3
30
0
Algorithm-
Step1 Start.
Step2 Declare suitable variables like p,c,x,n,r1,c1,c2,c3,k,n,r,i,j and array of limit
declare a 2-d 10.
Step3 Take an limit in N and perform p=N and c=n/2-1.
Step4 Start a loop from r=n/2-1 to r<=n/2 and perform a[c][r]=p++ and after
executing the loop do c++;
Step5 Start a loop from r=n/2 to r>=n/2-1,r—and perform a[c][r]=p++.
Step6 Perform c++.
Step7 Start the loops with j,c1,c2,c3 and i to store the numbers in circular order.
Step8 Now print the elements of 2-d array.
Step9 End.
Variable Discription :
* TYPE NAME PURPOSE
* int a[][] 2-D array
* int c,p counter variable
* int c1,c2,c3 columns of array
* int i,j looping variable
* int N input from user
PROGRAM-
import java.io.*;
class circular // class definition starts
{
public static void main(String args[])throws Exception//main function starts
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[10][10];
13. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
13
int p,c,x,n,r1,c1,c2,c3,k,N,r,i,j; // initializing variables
System.out.println("Enter the value of N");
N=Integer.parseInt(num.readLine());// input from the user
p=N;
System.out.println("enter the dimensions");
n=Integer.parseInt(num.readLine()); // input from the user
c=n/2-1;
for(r=n/2-1;r<=n/2;r++) // generating for loop
{
a[c][r]=p++;
}
c++; // counter variable
for(r=n/2;r>=n/2-1;r--) // generating for loop
{
a[c][r]=p++; // incrementing value
}
r=n/2-2;
r1=n/2+1;
x=n/2-2;
for(j=1;j<=n/2-1;j++) // generating for loop
{
for(c1=r;c1<=r1;c1++) // generating for loop
{
a[x][c1]=p++;
}
for(c2=x+1;c2<=r1;c2++) // generating for loop
{
a[c2][r1]=p++;
}
for(c3=r1-1;c3>=r;c3--) // generating for loop
{
a[r1][c3]=p++;
}
k=r1-1;
for(i=r1;i>r+1;i--) // generating for loop
{
a[k][c3+1]=p++;
k--;
}
r--;
r1=r1+1;
x--;
}
for(r=0;r<n;r++) // generating for loop
{
for(c=0;c<n;c++) // generating for loop
{
System.out.print(a[r][c]+" "+" "); // printing array
}
System.out.println();
14. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
14
}
}
}
OUTPUT-
I
In
np
pu
ut
t-
--
-
E
En
nt
te
er
r t
th
he
e v
va
al
lu
ue
e o
of
f N
N
5
5
e
en
nt
te
er
r t
th
he
e d
di
im
me
en
ns
si
io
on
ns
s
6
6
O
Ou
ut
tp
pu
ut
t-
--
-
2
21
1 2
22
2 2
23
3 2
24
4 2
25
5 2
26
6
4
40
0 9
9 1
10
0 1
11
1 1
12
2 2
27
7
3
39
9 2
20
0 5
5 6
6 1
13
3 2
28
8
3
38
8 1
19
9 8
8 7
7 1
14
4 2
29
9
3
37
7 1
18
8 1
17
7 1
16
6 1
15
5 3
30
0
3
36
6 3
35
5 3
34
4 3
33
3 3
32
2 3
31
1
(
(6
6)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o s
so
or
rt
t t
th
he
e e
el
le
em
me
en
nt
ts
s i
in
n a
a t
tw
wo
o d
di
im
me
en
ns
si
io
on
na
al
l a
ar
rr
ra
ay
y.
.
F
Fo
or
r e
eg
g—
—
15. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
15
Input--
2 31 54 87
1 2 3 47
64 58 27 30
34 21 2 28
Output—
87 64 58 54
47 34 31 30
28 27 21 3
2 2 2 1
Algorithm-
Step 1 Declare and initialize variables like r1,c1,temp,r,c and a double dimensional array
a[][].
Step 2 Store the numbers from the user in 2-d array.
Step 3 Begin a loop from r1=0 till r<4.
Step 4 Begin a loop from c1=0 till c1<4.
Step 5 Begin a loop from r=0 till r<4.
Step 6 Begin a loop from c=0 till c<4.
Step 7 Check if a[r1][c1]>a[r][c].
Step 8 If step7 is true then perform the swapping of elements.
Step 9 Print the final 2-d array at the end.
Step 10 End of process.
Variable Discription :
* TYPE NAME PURPOSE
* int a[][] Store 2-D array.
16. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
16
* int temp for swapping aray elements
* int r,r1 row of 2-D array
* int c,c1 column of 2-D array
PROGRAM-
import java.io.*;
class twodsorting // class definition starts
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int a[][]=new int[6][5];
int r,c,temp,r1,c1;
for(r=0;r<4;r++) // generating for loop
{
for(c=0;c<4;c++)
{
System.out.println("Enter your number");
a[r][c]=Integer.parseInt(num.readLine()); // input by user
}
}
for(r1=0;r1<4;r1++) // for loop
{
for(c1=0;c1<4;c1++)// for loop
{
for(r=0;r<4;r++)// for loop
{
for(c=0;c<4;c++)// for loop
{
if(a[r1][c1]>a[r][c]) // condition
{
/* swapping process begins */
temp=a[r1][c1];
a[r1][c1]=a[r][c];
a[r][c]=temp;
/* swapping process ends */
}
}
}
}
}
System.out.println("The sorted array is");
for(r=0;r<4;r++)
{
for(c=0;c<4;c++)
{
System.out.print(a[r][c]+" ");
}
17. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
17
System.out.println();
}
}
}
o
ou
ut
tp
pu
ut
t-
-
I
In
np
pu
ut
t—
—
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
2
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
3
31
1
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
5
54
4
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
8
87
7
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
1
1
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
2
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
3
3
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
4
47
7
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
6
64
4
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
5
58
8
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
27
7
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
3
30
0
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
3
34
4
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
21
1
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
2
E
En
nt
te
er
r y
yo
ou
ur
r n
nu
um
mb
be
er
r
2
28
8
O
Ou
ut
tp
pu
ut
t—
—
T
Th
he
e s
so
or
rt
te
ed
d a
ar
rr
ra
ay
y i
is
s
8
87
7 6
64
4 5
58
8 5
54
4
4
47
7 3
34
4 3
31
1 3
30
0
2
28
8 2
27
7 2
21
1 3
3
2
2 2
2 2
2 1
1
18. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
18
(
(7
7)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m i
in
n i
in
np
pu
ut
t t
tw
wo
o m
ma
at
tr
ri
ix
x a
an
nd
d p
pr
ri
in
nt
t t
th
he
e p
pr
ro
od
du
uc
ct
t o
of
f t
th
he
em
m.
Algorithm-
Step-1 Declare array A[][],B[][],C[][] and m,n,p,q for size.
Step-2 Input size of matrix A[][] in m,n.
Step-3 Input size of matrix B[][] in p,q.
Step-4 Input elements of matrix A[][] of m rows and n columns.
Step-5 Input elements of matrix B[][] of p rows and q columns.
Step-6 Check if n=p then goto step 7 otherwise goto step 15.
Step-7 Begins a loop for i from 0 to m-1 and repeat step 8 to 11.
Step-8 Begins a loop for j from 0 to q-1 and repeat step 9 to 11.
Step-9 Assign 0 to C[i][j].
Step-10 Begins a loop for k from 0 to n-1 and repeat step 11.
Step-11 Multiply matrix A[][] and B[][] as
C[i][j]=C[i][j] +(A[i][k]*B[k][j]).
Step-12 Print matrix A[][] of m rows and n columns using nested loops.
Step-13 Print matrix B[][] of p rows and q columns using nested loops.
Step-14 Print matrix C[][] of m rows and q columns using nested loops.
Step-15 End of algorithm.
Variable Discription :
* TYPE NAME PURPOSE
* a[][]
* int b[][] Store 2-D array.
* cr[][]
* int m,n row &column of matrix A
* int p,q row &column of matrix B
* int i,j looping variable
* int r,c row &column of cr[][]
PROGRAM-
import java.io.*;
class Product_Matrix // class starts
{
public static void main(String args[])throws Exception // main function starts
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int m,n,p,q,i,j,k,r,c; // declaring variables
int a[][]=new int[20][20];
int b[][]=new int[20][20];
int cr[][]=new int[20][20];
System.out.println("Input no. of rows and columns matrix A");
m=Integer.parseInt(num.readLine()); // input from user
n=Integer.parseInt(num.readLine()); // input from user
System.out.println("Input no. of rows and columns matrix B");
19. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
19
p=Integer.parseInt(num.readLine()); // input from user
q=Integer.parseInt(num.readLine()); // input from user
System.out.println("Input elements of A");
for(r=0;r<m;r++)
for(c=0;c<n;c++)
{
System.out.println("Enter numbers for matrix A");
a[r][c]=Integer.parseInt(num.readLine()); // input from user
}
System.out.println("Input elements of B");
for(r=0;r<p;r++)
for(c=0;c<q;c++)
{
System.out.println("Enter numbers for matrix B");
b[r][c]=Integer.parseInt(num.readLine()); // input from user
}
if(n==p) // condition
{
for(i=0;i<m;i++) // for loop
{
for(j=0;j<q;j++) // for loop
{
for(k=0;k<q;k++) // for loop
{
cr[i][j]+=a[i][k]*b[k][j]; // updating new 2-D array
}
}
}
}
System.out.println("Matrix A");
for(r=0;r<m;r++) // for loop
{
for(c=0;c<n;c++) // for loop
System.out.print(a[r][c]+"t"); // printing array
System.out.println();
}
System.out.println("Matrix B");
for(r=0;r<p;r++) // for loop
{
for(c=0;c<q;c++) // for loop
System.out.print(b[r][c]+"t"); // printing array
System.out.println();
}
System.out.println("Matrix C");
for(r=0;r<m;r++) // for loop
{
for(c=0;c<q;c++) // for loop
System.out.print(cr[r][c]+"t"); // printing array
System.out.println();
}
}
20. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
20
}
21. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
21
I
In
np
pu
ut
t—
—
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
2
2
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
3
3
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
4
4
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
5
5
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
6
6
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
7
7
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
8
8
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x A
A
9
9
I
In
np
pu
ut
t e
el
le
em
me
en
nt
ts
s o
of
f B
B
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
1
1
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
2
2
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
3
3
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
4
4
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
5
5
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
6
6
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
7
7
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
8
8
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r m
ma
at
tr
ri
ix
x B
B
9
9
O
Ou
ut
tp
pu
ut
t-
--
-
M
Ma
at
tr
ri
ix
x A
A
1
1 2
2 3
3
4
4 5
5 6
6
7
7 8
8 9
9
22. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
22
(
(8
8)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
a f
fo
ou
ur
r l
le
et
tt
te
er
r w
wo
or
rd
d a
an
nd
d p
pr
ri
in
nt
t a
al
ll
l t
th
he
e p
po
os
ss
si
ib
bl
le
e c
co
om
mb
bi
in
na
at
ti
io
on
ns
s o
of
f t
th
ha
at
t w
wo
or
rd
d.
.
M
Ma
at
tr
ri
ix
x B
B
1
1 2
2 3
3
4
4 5
5 6
6
7
7 8
8 9
9
M
Ma
at
tr
ri
ix
x C
C
3
30
0 3
36
6 4
42
2
6
66
6 8
81
1 9
96
6
1
10
02
2 1
12
26
6 1
15
50
0
23. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
23
Algorithm-
Step 1 Input a string of not more than 4 characters.
Step 2 Declare variables like i,j,k,l and in n store the length of string.
Step 3 Begin a loop for i till n.
Step 4 Begin a loop for j till n.
Step 5 Begin a loop for k till n.
Step 6 Begin a loop for l till n.
Step 7 Check if (i!=j&&i!=k&&i!=l&&j!=k&&j!=l&&k!=l) then repeat steps 8,9,10,11.
Step 8 Print the character at i position.
Step 9 Print the character at j position.
Step 10 Print the character at k position.
Step 11 Print the character at l position.
Step 12 End of algorithm.
Variable Discription :
TYPE NAME PURPOSE
int n Store length of str1
String str1 to add character.
Int i looping variable
Int j looping variable
Int p counter variable
char ch to store present character
char ch2 to compare with ch2
PROGRAM-
import java.io.*;
class permutation
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
String str;
int n,j,k,l,i;
System.out.println("Enter your four letter word");
str=num.readLine();
n=str.length();
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
24. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
24
{
for(l=0;l<n;l++)
{
if(i!=j&&i!=k&&i!=l&&j!=k&&j!=l&&k!=l)
{
System.out.print(str.charAt(i));
System.out.print(str.charAt(j));
System.out.print(str.charAt(k));
System.out.print(str.charAt(l));
System.out.println();
}
}
}
}
}
}
}
o
ou
ut
tp
pu
ut
t-
-
I
In
np
pu
ut
t-
-
E
En
nt
te
er
r y
yo
ou
ur
r f
fo
ou
ur
r l
le
et
tt
te
er
r w
wo
or
rd
d
R
Ra
aj
ju
u
O
Ou
ut
tp
pu
ut
t-
--
-
r
ra
aj
ju
u
r
ra
au
uj
j
r
rj
ja
au
u
r
rj
ju
ua
a
r
ru
ua
aj
j
r
ru
uj
ja
a
25. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
25
a
ar
rj
ju
u
a
ar
ru
uj
j
a
aj
jr
ru
u
a
aj
ju
ur
r
a
au
ur
rj
j
a
au
uj
jr
r
j
jr
ra
au
u
j
jr
ru
ua
a
j
ja
ar
ru
u
j
ja
au
ur
r
j
ju
ur
ra
a
j
ju
ua
ar
r
u
ur
ra
aj
j
u
ur
rj
ja
a
9
9)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
a m
ma
at
tr
ri
ix
x a
an
nd
d r
re
em
mo
ov
ve
e t
th
he
e c
ce
en
nt
tr
ra
al
l n
nu
um
mb
be
er
rs
s a
an
nd
d t
th
he
en
n p
pr
ri
in
nt
t t
th
he
e s
su
um
m o
of
f r
re
em
ma
ai
in
ni
in
ng
g
n
nu
um
mb
be
er
rs
s i
in
n t
th
he
e m
ma
at
tr
ri
ix
x.
.
I
If
f t
th
he
e i
in
np
pu
ut
t i
is
s-
-
O
Or
ri
ig
gi
in
na
al
l M
Ma
at
tr
ri
ix
x
26. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
26
1
1 2
2 3
3
4
4 5
5 6
6
7
7 8
8 9
9
T
Th
he
en
n t
th
he
e o
ou
ut
tp
pu
ut
t i
is
s-
-
S
Sq
qu
ua
ar
re
e M
Ma
at
tr
ri
ix
x
1
1 2
2 3
3
4
4 6
6
7
7 8
8 9
9
S
Su
um
m i
is
s :
: 4
40
0
Algorithm-
Step 1 Start.
Step 2 Declare variables like r,c,m=0,s=0,l=n and a 2d array of limit n which is to be
entered from the user.
Step 3 Start a while loop such that n>1.
Step 4 Start a loop in which r=m,c=m tll c<l-m and then perform s=s+a[r][c] and then
print it.
Step 5 Change the line..
Step 6 Start for loop from r=m+1 till r<l-m-1.
Step7 Start another loop from c=m till c<l-m.
Step8 Check if (c==m||c==l||c==l-m-1).
Step9 Start another loop from r=l-m-1 till c=m and repeat second half of step4.
Step10 Initialize n=n-2,m++ and s=0.
Step11 End.
Variable Discription :
TYPE NAME PURPOSE
int a[][] Store 2-D array.
int n input by user
int r row of 2-D array
int c column of 2-D array
int s Sum of elements
PROGRAM-
import java.io.*;
27. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
27
class Square_sum
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter order of matrix(odd)");
int n=Integer.parseInt(num.readLine());
int a[][]=new int[n][n];
int r,c,m=0,s=0,l=n;
for(r=0;r<n;r++)
for(c=0;c<n;c++)
{
System.out.println("Enter numbers for array");
a[r][c]=Integer.parseInt(num.readLine());
}
System.out.println("Original Matrix");
for(r=0;r<n;r++)
{
for(c=0;c<n;c++)
System.out.print(a[r][c]+"t");
System.out.println();
}
System.out.println("Square Matrix");
while(n>1)
{
for(r=m,c=m;c<l-m;c++)
{
s=s+a[r][c];
System.out.print(a[r][c]+"t");
}
System.out.println();
for(r=m+1;r<l-m-1;r++)
{
for(c=m;c<l-m;c++)
{
if(c==m||c==l-m-1)
{
s=s+a[r][c];
System.out.print(a[r][c]+"t");
}
else
System.out.print("t");
}
System.out.println();
}
for(r=l-m-1,c=m;c<l-m;c++)
{
s=s+a[r][c];
System.out.print(a[r][c]+"t");
}
System.out.print("Sum is : "+s);
28. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
28
System.out.print("n");
n-=2;
m++;
s=0;
}
}
}
o
ou
ut
tp
pu
ut
t-
-
(
(1
10
0)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
a l
li
im
mi
it
t a
an
nd
d p
pr
ri
in
nt
t a
al
ll
l t
th
he
e l
lu
uc
ck
ky
y n
no
os
s.
.
I
In
np
pu
ut
t-
--
-
E
En
nt
te
er
r o
or
rd
de
er
r o
of
f m
ma
at
tr
ri
ix
x(
(o
od
dd
d)
)
3
3
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
1
1
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
2
2
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
3
3
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
4
4
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
5
5
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
6
6
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
7
7
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
8
8
E
En
nt
te
er
r n
nu
um
mb
be
er
rs
s f
fo
or
r a
ar
rr
ra
ay
y
9
9
O
Or
ri
ig
gi
in
na
al
l M
Ma
at
tr
ri
ix
x
1
1 2
2 3
3
4
4 5
5 6
6
7
7 8
8 9
9
S
Sq
qu
ua
ar
re
e M
Ma
at
tr
ri
ix
x
1
1 2
2 3
3
4
4 6
6
7
7 8
8 9
9 S
Su
um
m i
is
s :
: 4
40
0
29. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
29
F
Fo
or
r e
eg
g-
-i
if
f t
th
he
e i
in
np
pu
ut
t i
is
s 1
10
0.
.
T
Th
he
en
n t
th
he
e O
Ou
ut
tp
pu
ut
t i
is
s=
=1
1,
,3
3,
,7
7.
.
Algorithm-
Step 1 Declare variables like i,a[100],n, k,j,ctr=0,step=1.
Step 2 Input the limit in n.
Step 3 Begin a for loop for i from 0 to n and store natural numbers till limit in the array
a[].
Step 4 Begin a for loop for i from 0 to n-ctr
Step 5 Begin a for loop for j from i+1 to n-ctr and j=j+step.
Step 6 Begin a for loop for k from j to n and store numbers as a[k]=a[k+1].
Step 7 Add 1 to ctr at the end of k loop.
Step 8 Add 1 to step at the end of j loop.
Step 9 Print lucky numbers by the loop i from 0 to n-ctr.
Step 10 End of algorithm.
Variable Discription :
TYPE NAME PURPOSE
int n input from user
int i,j looping variable
int ctr,step counter variable
PROGRAM-
import java.io.*;
class lucky
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int n,i,j,k,ctr=0,step=1;
int a[]=new int[100];
System.out.println("Enter the limit");
n=Integer.parseInt(num.readLine());
for(i=0;i<n;i++)
a[i]=i+1;
for(i=0;i<n-ctr;i++)
{
for(j=i+1;j<(n-ctr);j+=step)
{
for(k=j;k<n;k++)
{
a[k]=a[k+1];
}
ctr++;
}
30. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
30
step++;
}
System.out.println("Lucky number are=");
for(i=0;i<(n-ctr);i++)
System.out.println(a[i]+" ");
}
}
output-
I
In
np
pu
ut
t-
-
E
En
nt
te
er
r t
th
he
e l
li
im
mi
it
t
1
10
0
O
Ou
ut
tp
pu
ut
t
L
Lu
uc
ck
ky
y n
nu
um
mb
be
er
r a
ar
re
e=
=
1
1
3
3
7
7
(
(1
11
1)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t n
n n
nu
um
mb
be
er
rs
s i
in
n a
a a
ar
rr
ra
ay
y a
an
nd
d a
ar
rr
ra
an
ng
ge
e i
in
n g
gi
iv
ve
en
n m
ma
an
nn
ne
er
r w
wi
it
th
ho
ou
ut
t u
us
si
in
ng
g a
an
no
ot
th
he
er
r
a
ar
rr
ra
ay
y.
.
S
Sh
hi
if
ft
t t
th
he
e l
la
ar
rg
ge
es
st
t n
nu
um
mb
be
er
r a
at
t t
th
he
e m
mi
id
dd
dl
le
e p
po
os
si
it
ti
io
on
n (
(i
i.
.e
e N
N/
/2
2 i
in
nd
de
ex
x n
nu
um
mb
be
er
r)
) s
se
ec
co
on
nd
d l
la
ar
rg
ge
es
st
t b
be
ef
fo
or
re
e t
th
he
e m
mi
id
dd
dl
le
e
a
an
nd
d s
so
o o
on
n.
.
Algorithm-
31. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
31
Step1. Declare variables n,i,j,k,k1,t.
Step 2. Input size of array in n from user.
Step 3. Declare array a[] of size (n*2).
Step 4. Assign (n+n)-4 to k and (n+n)-2 to k1.
Step 5. Input n numbers from user.
Step 6. Begin loop for i from 0 to n-1 and repeat step 7 to 12.
Step 7. Begin loop for j from i+1 to n-1 and repeat step 8 to12.
Step 8. if(a[i]<a[j])
Step 9. Assign value of a[i] to t.
Step 10. Assign value of a[j] to a[i].
Step 11. Assign value of t to a[j].
Step 12. Assign 0 to t.
Step 13. Assign a[0] to a[(n+n)-3].
Step 14. Begin loop for i from 1 to n-1 and repeat step 15 to 20.
Step 15. if(i%2!=0)
Step 16. Assign a[i] to a[k].
Step 17. Assign k-1 to k.
Step 18. else if(i%2= =0)
Step 19. Assign a[i] to a[k1].
Step 20. Assign k1+1 to k1.
Step 21. Print elements of array a[] from n to (n+n)-1.
STEP 22. END
Variable Discription :
TYPE NAME PURPOSE
int a[] array
int temp for swapping values
int x,y,z looping variables
int n input from user
PROGRAM-
import java.io.*;
class arraypat
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int a[]=new int[20];
int n,x,y,z,p,temp;
System.out.println("enter the number of elements");
n=Integer.parseInt(num.readLine());
for(x=0;x<n;x++)
{
System.out.println("enter the element");
a[x]=Integer.parseInt(num.readLine());
}
p=(n/2);
32. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
32
n--;
for(x=0;x<p;x++)
{
for(y=x;y<=(n-x);y++)
{
for(z=y;z<=(n-x);z++)
{
if(a[y]>a[z])
{
temp=a[y];
a[y]=a[z];
a[z]=temp;
}
}
}
for(y=x+1;y<=(n-x);y++)
{
for(z=y;z<=(n-x);z++)
{
if(a[y]<a[z])
{
temp=a[y];
a[y]=a[z];
a[z]=temp;
}
}
}
}
if(n%2==0)
{
for(x=0;x<p;x++)
{
temp=a[x];
a[x]=a[n-x];
a[n-x]=temp;
}
}
System.out.println("the final array is");
for(x=0;x<=n;x++)
{
System.out.println(a[x]);
}
}
}
output-
Input—
enter the number of elements
6
33. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
33
enter the element
45
enter the element
69
enter the element
5
enter the element
88
enter the element
4
enter the element
1
Output--
the final array is
1
5
69
88
45
4
(
(1
12
2)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o i
in
np
pu
ut
t a
a p
po
os
si
it
ti
iv
ve
e i
in
nt
te
eg
ge
er
r a
an
nd
d p
pr
ri
in
nt
t a
al
ll
l t
th
he
e c
co
om
mb
bi
in
na
at
ti
io
on
ns
s o
of
f c
co
on
ns
se
ec
cu
ut
ti
iv
ve
e n
na
at
tu
ur
ra
al
l
n
nu
um
mb
be
er
r.
.
E
Eg
g-
-2
27
7;
;
2
2+
+3
3+
+4
4+
+5
5+
+6
6+
+7
7=
=2
27
7.
.
8
8+
+9
9+
+1
10
0=
=2
27
7.
.
1
13
3+
+1
14
4=
=2
27
7.
.
Algorithm-
Step1.Declare array a[][] and variable i,j,i1,s,x,k.
Step 2.Initialize s and k with value 0.
Step 3.Input value of x from user.
34. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
34
Step 4.Begin loop for i1 from 1 to x-1 and repeat step 5 to 15.
Step 5.Begin loop for i from i1 to x-1 and repeat step 6 to14.
Step 6.if(s!=x)
Step 7.Assign value of s+i to s.
Step 8.Assign value of I to a[k].
Step 9.Assign value of k+1 to k.
Step 10.else
Step 11.Begin loop for j from 0 to k-1 and repeat step 12.
Step 12. Print the value of a[j].
Step 13.Print value of a[k-1].
Step 14.Assign 0 to k and s.
Step 15. Assign 0 to k and s.
step 16. end
Variable Discription :
* TYPE NAME PURPOSE
* int n input from user
* int sum to find sum
* int c (for loop)
* to print consecutive pairs
PROGRAM-
import java.io.*;
class consnatural
{
public static void main(String args[])throws Exception
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int c,i,j,sum=0,n;
System.out.println("Enter a number");
n=Integer.parseInt(num.readLine());
System.out.println("Consecutive pairs are");
for(i=1;i<n;i++)
{
for(j=i;j<n;j++)
{
sum=sum+j;
if(sum==n)
{
for(c=i;c<=j;c++)
{
System.out.print(c+" ");
}
System.out.println();
35. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
35
}
}
sum=0;
}
}
}
output-
Input—
Enter a number
27
Output--
Consecutive pairs are
2 3 4 5 6 7
8 9 10
13 14
(
(1
13
3)
) W
Wr
ri
it
te
e a
a p
pr
ro
og
gr
ra
am
m t
to
o p
pr
ri
in
nt
t t
th
he
e d
di
ia
am
mo
on
nd
d p
pa
at
tt
te
er
rn
n a
as
s s
sh
ho
ow
wn
n.
.
*
***
*****
*******
********
*******
*****
***
*
Algorithm-
36. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
36
Step1 Start.
Step2 Declare suitable variables I,sp,j,n=4,i1,sp1,j1,n1.
Step3 Start a loop from i=1 till i<=9
Step4 Start a loop from sp=1 till sp<=n.
Step5 Start a loop from j=1 till j<=i .
Step6 Start a loop from i1=7 till i1>=1.
Step7 Start a loop from sp=1 till n1 to give the required spacing.
Step9 Start another loop from j1=1 till i1 and then print “*” and then perform n1 and
then change line.
Step 10 End.
Variable Discription :
TYPE NAME PURPOSE
int n input from user
int i,j looping variables for upper triangle
int i1,j1 looping variables for lower triangle
int sp to give limited spaces
PROGRAM-
import java.io.*;
class diamondpat // class definition starts
{
public static void main()throws Exception // main function starts
{
BufferedReader num=new BufferedReader(new InputStreamReader(System.in));
int i,sp,j,n=4,i1,sp1,j1,n1=1; // initializing variables
for(i=1;i<=9;i=i+2) // generating loop
{
for(sp=1;sp<=n;sp++) // loop to give spaces
{
System.out.print(" ");
}
for(j=1;j<=i;j++) // inner loop to print *
{
System.out.print("*");
}
System.out.println(); // chaning line
37. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
37
n--;
}
for(i1=7;i1>=1;i1=i1-2) // generating loop
{
for(sp1=1;sp1<=n1;sp1++)
{
System.out.print(" "); // loop to give spaces
}
for(j1=1;j1<=i1;j1++)
{
System.out.print("*"); // inner loop to print *
}
System.out.println(); // chaning line
n1++;
}
} // main function ends
} // class ends
Output—
*
***
*****
*******
********
*******
*****
***
*
38. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
38
PROGRAM 14
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
39. 49 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
39
s o l u t i o n
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.readLine());
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(NumberFormatException e)
{}
if(n>0)
{if((c+n)<=90)
/*Decoding String*/
System.out.print((char)(c+n));
else {c=c+n;
c=c%10;
c=65+(c-1);
System.out.print((char)(c));
}}
else if(n<0)
{n1=Math.abs(n);
if((c-n1) >=65)
System.out.print((char) (c-n1));
else {if(c>65)
c=c-65;
else c=n1;
System.out.print((char)(90-(c-1)));
}}
else if (n==0)
{System.out.println("no change "+name);
break;
}}}}
40. PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
40
51 | 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
var i abl e description
No. Name Type Method Description
1 br BufferedReader compute() BufferedReader object
2 name String compute() input string
3 n int compute() decode number
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 NumberFormatException compute() NumberFOrmatException object
output
41. 52 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
41
PROGRAM 15
To Display the Entered String
in Alphabetical Order
ALGORITHM
STEP 1 - START
STEP 2 - str = "" , l = 0
STEP 3 - INPUT string str
STEP 4 - l =str.length()
STEP 5 - FROM i=0 to i<l REPEAT STEP 6
STEP 6 - c[i] = str.charAt(i)
STEP 7 - FROM i=0 to i<l-1 REPEAT STEP 8
STEP 8 - FROM j=0 to i<l-1 REPEAT STEP 9
STEP 9 - temp =c[j], c[j] = c[j+1] , c[j+1] = temp
STEP 10 - FROM i=0 to i<l REPEAT STEP 11
STEP 11 - PRINT c[i]
STEP 12 – END
42. 52 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
42
s o l u t i o n
import java.io.*;
class Alpha
{String str;
int l;
char c[] = new char[100];
public Alpha() //Alpha() constructor
{str = "";
l =0;
}
public void readword() throws IOException //function to read input string
{System.out.println("enter word - ");
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
l = str.length();
}
public void arrange() //function to arrange string in ascending order
{int i,j;
char temp;
for(i=0;i<l;i++)
{c[i]= str.charAt(i);
}
for(i=0;i<l-1;i++) //loops for swapping of 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;
}}}}
public void display() //function to display the rearranged string
{System.out.println();
for(int i=0;i<l;i++)
{System.out.print(c[i]);
}}
public static void main(String args[]) throws IOException //main function
{Alpha obj = new Alpha();
obj.readword();
obj.arrange();
obj.display();
}}
43. 52 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
43
var i abl e description
No. Name Type Method Description
1 br BufferedReader readword() BufferedReader object
2 str String - input string
3 l int - length
4 c char[] - character array
5 i int readword() loop variable
6 j int readword() loop variable
7 temp char readword() temporary storage
8 obj Alpha main() Alpha object
output
44. 52 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
44
PROGRAM 16
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
s o l u t i o n
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);
}}
45. 52 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
45
var i abl e description
No. Name Type Method Description
1 br BufferedReader 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
46. PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
46
57 | 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 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
s o l u t i o n
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
}}
47. 58 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
47
var i abl e description
No. Name Type Method Description
1 br BufferedReader main() BufferedReader object
2 z int main() length of string
3 a String main() input string
4 x int main() space counter
5 y int main() loop variable
output
48. 58 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
48
PROGRAM 18
To create a string and replace
all vowels with *
ALGORITHM
STEP 1 - START
STEP 2 - a = "Computer Applications"
STEP 3 - x= 0
STEP 4 - FROM z =0 to z<a.length() REPEAT STEP 5
STEP 5 - if(a.charAt(z)=='a'||a.charAt(z)=='e'||a.charAt(z)=='i'||a.charAt(z)=='o'||a.charAt(z)=='u’) THEN a.setCharAt(z,'*')
STEP 6 - PRINT "New String -"+a
STEP 7 – END
s o l u t i o n
import java.io.*;
class VowelReplace
{public static void main(String args[])throws IOException //main function
{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter a String”);
StringBuffer a=new StringBuffer(br.readLine()); //accepting a string
System.out.println("Original String -"+a);
int z=0;
for(z=0;z<a.length();z++) //loop for replacing vowels with "*"
{if(a.charAt(z)=='a'||a.charAt(z)=='e'||a.charAt(z)=='i'||a.charAt(z)=='o'||a.charAt(z)=='u')
a.setCharAt(z,'*');
}System.out.println("New String -"+a); //displaying the result
}}
49. 58 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
49
var i abl e description
No. Name Type Method Description
1 br BufferedReader main() BufferedReader object
2 a StringBuffer main() StringBuffer object of input string
3 z Int main() loop variable
output
50. 58 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
50
PROGRAM 19
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
STEP 4 - FROM y =0 to y<5 REPEAT STEP 5
STEP 5 - PRINT (a[x][y]+" "
STEP 6 - FROM x =0 to x<5 REPEAT STEP 7
STEP 7 - FROM y =0 to y<5 REPEAT STEP 8
STEP 8 - Sum=Sum+a[x][y]
STEP 9 - PRINT Sum
STEP10 – END
s o l u t i o n
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.readLine()); //accepting array element
51. 58 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
51
a[x][y]=z;
}}
System.out.println("Array -");
for(x=0;x<5;x++)
{for(y=0;y<5;y++)
//loop for printing array
{System.out.print(a[x][y]+" ");
}
System.out.print("n");
}
for(x=0;x<5;x++)
{for(y=0;y<5;y++)
{Sum=Sum+a[x][y];
}}
//loop for printing sum of array elements
System.out.println("Sum of Array elements="+Sum);
}}
//displaying sum
var i abl e description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 a int[][] main() input array
3 x Int main() loop variable
4 y Int main() loop variable
5 z Int main() input element
6 Sum main() main() Sum of all elements
output
52. 63 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
52
PROGRAM 20
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
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 9 and STEP 10
STEP 7 - FROM y =0 to y<4 REPEAT STEP 8
STEP 8 - Sum=Sum+a[x][y] ,
STEP 9 - PRINT Sum
STEP 10 - Sum = 0
STEP11 – END
s o l u t i o n
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;
}}
53. 63 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
53
System.out.println("Array -"); //printing the array 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 "+(y+1)+" is "+Sum);
Sum=0;
}}}
//printing sum of coloumn
var i abl e description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 a int[][] main() input array
3 x int main() loop variable
4 y int main() loop variable
5 z int main() input element
6 Sum int main() Sum of each couloumn
output
54. PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
54
65 | 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 21
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
s o l u t i o n
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 -");
55. PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
55
o j e c t
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{System.out.print(a[x][y]+" ");
}
System.out.print("n");
}
y=0;
for(x=0;x<4;x++)
{Sum=Sum+a[x][y];
y=y+1;
}
//displaying array
//loop for finding sum of diagonal
System.out.println("Sum of diagonal is "+Sum); //displaying the sum of diagonal
Sum=0;
}}
var i abl e description
No. Name Type Method Description
1 aa BufferedReader main() BufferedReader object
2 a int[][] main() input matrix
3 x Int main() loop variable
4 y Int main() loop variable
5 Sum Int main() Sum of diagonals
6 z Int main() input element
output
56. 67 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
56
PROGRAM 22
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
s o l u t i o n
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
57. 67 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
57
/*calculating commission*/
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*sales;
System.out.println("Commission of the employee="+comm); //displaying commission
}}
var i abl e description
No. Name Type Method Description
1 Aa BufferedReader main() BufferedReader object
2 Sales double main() sales
3 comm. double main() commision
output
58. 69 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
58
PROGRAM 23
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
s o l u t i o n
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","LXXX","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]);
}}
59. 69 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
59
var i abl e description
No. Name Type Method Description
1 in DataInputStream main() DataInputStream object
2 num Int main() input number
3 hund String[] main() array storing 100th
position
4 ten String[] main() array storing 10th
position
5 unit String[] main() array storing units position
output
60. 71 | 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
PREM PRAKASH SAINI ISC COMPUTER SCIENCE PROJECT
60
PROGRAM 24
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
s o l u t i o n
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;
}}
61. 71 | 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
var i abl e description
No. Name Type Method Description
1 br BufferedReader main() BufferedReader object
2 ob C2F main() C2F object
3 temp double main() calculated Fahrenheit temperature
4 celcius double convert() input temperature in Celsius
5 far double convert() Calculated Fahrenheit temperature
output