Computer
Computer
COMPUTER
SCIENCE PROJECT
Shoaib Qureshi
Computer Science Project |2
Step 1 – Start.
Step2 –Get the length of sides inputted by the user.
Step3 – Calculate perimeter by adding lengths of
all the sides.
Step4- Calculate area by formula(√[s × (s – a) ×
(s – b) × (s – c)]) where s=(l1+l2+l3)/2).
Step5-Stop.
Shoaib Qureshi
Computer Science Project |3
Program –
class Program1
{
void main(int l1, int l2, int l3)
{
int s=(l1+l2+l3)/2;
int P = 2*s;
int area = (int)Math.sqrt(s*(s-l1)*(s-l2)*(s-l3));
System.out.println("first side is" +l1);
System.out.println("second side is "+l2);
System.out.println("third side is "+l3);
System.out.println("area is "+area);
System.out.println("perimeter is "+P);
}
}
Shoaib Qureshi
Computer Science Project |4
Output-
Input
l1=5 l2=4 l3=3
Output
first side is 3
second side is 4
third side is 5
area is 6
perimeter is 12
Shoaib Qureshi
Computer Science Project |5
Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return false when the value of n is zero as
base case.
Step4 – Call the function to go for another round
without a loop and keep checking for equality.
Step5 – Stop.
Shoaib Qureshi
Computer Science Project |6
Program-
class Program2
{
boolean search(int N,int x)
{
if(N==0)
return false;
else
{
int d = N%10;
if(d==x)
{
return true;
}
else
{
return search(N/10,x);
}
Shoaib Qureshi
Computer Science Project |7
}
}}
Output-
Input
N=720
X=2
Output
True
Shoaib Qureshi
Computer Science Project |8
Step 1 – Start.
Step2 –Get number inputted by user.
Step3 – Calculate sum of digit.
Step4 -Check whether sum is equal to 9 or not and
print neon if it is else print not a neon number.
Step5-Stop.
Program –
Shoaib Qureshi
Computer Science Project |9
class Program3
{
public static void main(int N)
{
int s = 0;
while(N>0)
{
int d=N%10;
s=s+d;
N=N/10;
}
if(s==9)
System.out.println("Neon");
else
System.out.println("Not Neon");
}
}
Output-
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 10
Input
N=324
Output
Neon
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 11
Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Make a copy of number.
Step4- Calculate the sum of digit by a while loop.
Step5-Now check if the copy of number is divisible
by sum of digit or not if it is then print Niven else it
is not Niven.
Step6-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 12
Program-
class Program4
{
void main(int N)
{
int s=0, M=N;
while(N>0)
{
int d=N%10;
s=s+d;
N=N/10;
}
if(M%s==0)
System.out.println("Niven Number");
else
System.out.println("Not a Niven Number");
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 13
Output-
Input
N=126
Output
Niven Number
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 14
Step 1 – Start.
Step2 – Form a function for sum and get the value
of n inputed by the user.
Step3 – Return 1 when the value of n is one as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 15
Program-
class Program5
{
int sum(int N)
{
if(N==1)
return 1;
else
{
return N+sum(N-1);
}
}}
Output-
Input
N=6
Output
21
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 16
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 17
Step 1 – Start.
Step2 – Form a function for finding fibonaci term.
Step3 – If N is one return 0 as base case and if N is
2 return 1 as base case.
Step4 – Call the function to go for another round
without a loop and keep checking for fibonacci
term.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 18
Program-
class Program6
{
int Fibo(int N)
{
if(N==1)
{
return 0;
}
else if(N==2)
{
return 1;
}
else
{
return Fibo(N-1)+Fibo(N-2);
}
}}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 19
Output-
Input
N=4
Output
2
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 20
Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep adding 1.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 21
Program-
class Program7
{
int countdigit(int N)
{
if(N==0)
return 0;
else
{
int d = N%10;
return 1+countdigit(N/10);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 22
Output-
Input
N=720
Output
3
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 23
Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Check if the number is greater than 3 or not.
Step4- Make a loop from 3 to n.
Step5-Print sum of all consecutive numbers in
between.
Step6-Stop.
Program-
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 24
class Program8
{
void main(int n)
{
if (n < 3)
{
System.out.println("triangular number are
greater than n");
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 25
}
Output-
Input
N=7
Output
Triangular Numbers from 3 to 7:
3
6
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 26
Step 1 – Start.
Step2 – Form a while loop reverse the number after
making a copy of it.
Step3 – Check the equality of reverse number with
original number.
Step4 - If equal print palindrome else print not
palindrome.
Step5 – Stop.
Program-
class Program9
{
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 27
void main(int N)
{
int R=0;
int t = N;
while(t>0)
{
int d = t%10;
R = R*10+d;
t=t/10;
}
if(N == R)
System.out.println(N+ "is a Palindrome no");
else
System.out.println(N+ "is not a Palindrome
no"); } }
Output-
Input
N=525
Output
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 28
525 is a palindrome
number.
Step 1 – Start.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 29
Program-
class Program10
{
void main(int n)
{
int F=0;
for(int i=1;i<=n-1;i++)
{
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 30
if(i*(i+1)==n)
F=1;
}
if(F==1)
System.out.println("Pronic");
else
System.out.println("Not Pronic");
}
}
Output –
Input
N=6
Output
Pronic Number
inputted by
user
i int Loop variable
from 1 to N-1.
F int Flag to check
for
confirmation of
equality.
Step 1 – Start.
Step2 –Get the number inputted by the user.
Step3 – Convert the number from decimal to binary.
Step4- Count the number f 1’s in the binary number.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 32
Program –
class Program11
{
void main(int n)
{
int c=0,p=0,bin=0;
while (n > 0)
{
int d = n % 2;
if (d == 1)
c++;
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 33
Output –
Input
N=14
Output
Not an Evil Number
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 34
Step 1 – Start.
Step2 –Get the radius of circle inputted by the user.
Step3 – Calculate area by formula(A=2*3.14*r*r).
Step4- Calculate circumference by
formula(C=(2*3.14*r)).
Step5-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 36
Program –
class Program12
{
void main(double r)
{
double area = 3.14*r*r;
double circumference = 2*3.14*r;
System.out.println("Radius is "+r);
System.out.println("Area is "+area);
System.out.println("Circumference is
"+circumference);
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 37
Output –
Input
radius=5
Output
Radius is 5.0
Area is 78.5
Circumference is 31.40
Step 1 – Start.
Step2 –Get the radius and height of cylinder
inputted by the user.
Step3 – Calculate volume by
formula(V=2*3.14*r*r*h).
Step4- Calculate surface area by
formula(SA=(2*3.14*r*r)+(2*3.14*r*h)).
Step5-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 39
Program –
class Program13
{
void main(int radius, int height)
{
double volume = 3.14*radius*radius*height;
double area =
(2*3.14*radius*height)+(2*3.14*radius*radius);
System.out.println("radius is" +radius);
System.out.println("height is "+height);
System.out.println("volume is "+volume);
System.out.println("area is "+area);
}}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 40
Output-
Input
radius=5
height=10
Output
radius is 5
height is 10
volume is 785.0
area is 471.0
cylinder
volume int Volume of a
cylinder
area int Area of a
cylinder
Program 14)WAP in java to calculate
area and perimeter of square or
rectangle.
Step 1 – Start.
Step2 –Get the length and breadth inputted by the
user.
Step3 – Calculate area by formula
(A=length*breadth).
Step4- Calculate perimeter by formula
(P=2*(length+breadth)).
Step5-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 42
Program –
class Program14
{
void main(int length, int breadth)
{
int area = length*breadth;
int perimeter = 2*(length+breadth);
System.out.println("length is" +length);
System.out.println("breadth is "+breadth);
System.out.println("area is "+area);
System.out.println("perimeter is "+perimeter);
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 43
Output –
Input
length=5
breadth=6
Output
length is 5
breadth is 6
area is 30
perimeter is 22
Step 1 – Start.
Step2 –Get the principal, rate and time inputted by
the user.
Step3 – Calculate simple interest by formula (SI
=(P*R*T)/100).
Step4-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 45
Program –
class Program15
{
void main(double p, double r, double t)
{
double SI=(p*r*t)/100.0;
System.out.println("Principal is "+p);
System.out.println("Rate is "+r);
System.out.println("Time is "+t);
System.out.println("Simple Interest is "+SI);
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 46
Output –
Input
P=10,000
R=15%
T=5 years
Output
Principal is 10000.0
Rate is 15.0
Time is 5.0
Simple Interest is 7500.0
Step 1 – Start.
Step2 –Get the length of word inputted.
Step3 – Make a loop from starting to the second
last character.
Step4 -Get the characters and print them
simultaneously.
Step5-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 48
Program –
class Program16
{
public static void main(String nm)
{
int l = nm.length();
for(int i=0;i<=l-2;i++)
{
char d = nm.charAt(i);
char e = nm.charAt(i+1);
System.out.println(d+" "+e);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 49
Output –
Input
nm=“Rajesh”
Output
Ra
aj
je
es
sh
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 50
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 51
Step7-Stop
Program –
class Program17
{
public static void main(int N)
{
int n2 = N * 2;
int n3 = N * 3;
String concatstr=N + "" + n2 + n3;
boolean found = true;
for(char c = '1'; c <= '9'; c++)
{
int count = 0;
for(int i = 0; i < concatstr.length(); i++)
{
char ch = concatstr.charAt(i);
if(ch == c)
count++;
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 52
}
if(count > 1 || count == 0)
{
found = false;
break;
}
}
if(found)
System.out.println(N + " is a fascinating
number.");
else
System.out.println(N + " is not a fascinating
number.");
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 53
Output –
Input
N=327
Output
525 is a fascinating
number.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 54
Step 1 – Start.
Step2 – Make a loop from 1 to that number.
Step3 – Check the divisibility of number with each
number in the loop and count the divisibility
condition to be zero.
Step4 -Check that counter is 2 or not and print true
or false according to it.
Step5-Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 55
Program –
class Program18
{
boolean isprime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 56
Output –
Input
N=13
Output
True
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 57
Step 1 – Start.
Step2 – Form a function for factorial and get the
value of n inputed by the user.
Step3 – Return 1 when the value of n is one as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 58
Program –
class Program19
{
int Fact(int N)
{
if(N==1)
return 1;
else
{
return N*Fact(N-1);
}
}
}
Output –
Input
N=6
Output
720
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 59
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 60
Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputted by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 61
Program –
class Program20
{
void extract(int N)
{
if(N==0)
return;
else
{
int d = N%10;
System.out.println(d);
extract(N/10);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 62
Output –
Input
N=720
Output
0
2
7
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 63
Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep adding the digit.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 64
Program –
class Program21
{
int sumdigit(int N)
{
if(N==0)
return 0;
else
{
int d = N%10;
return d+sumdigit(N/10);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 65
Output –
Input
N=720
Output
9
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 66
Step 1 – Start.
Step2 – Form a function for extracting digit and get
the value of n inputed by the user.
Step3 – Return when the value of n is zero as base
case.
Step4 – Call the function to go for another round
without a loop and keep multiplying the digits.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 67
Program –
class Program22
{
int productdigit(int N)
{
if(N==0)
return 1;
else
{
int d = N%10;
return d*productdigit(N/10);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 68
Output –
Input
N=720
Output
3
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 69
Step 1 – Start.
Step2 – Form a function for finding hcf by long
division method.
Step3 – If the first number is divisible by another
one return it as base case.
Step4 – Call the function to go for another round
without a loop and keep checking for divisibility.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 70
Program –
class Program23
{
int HCF(int A,int B)
{
if(B%A==0)
return A;
else
{
int R = B%A;
B=A;
A=R;
return HCF(A,B);
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 71
Output –
Input
A=8
B=12
Output
4
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 72
Step 1 – Start.
Step2 – Form a function for converting decimal to
binary.
Step3 – If N is one return 0 as base case.
Step4 – Call the function to go for another round
without a loop and keep dividing by 2.
Step5 – Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 73
Program –
class Program24
{
int DecToBin(int N)
{
if(N==0)
{
return 0;
}
else
{
int d = N%2;
return DecToBin(N/2)*10+d;
}
}
}
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 74
Output –
Input
N=4
Output
100
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 75
Step 1 – Start.
Step2 – Form a while loop to count the no. of digits
in the number after making a copy of it.
Step3 – Calculate square of number.
Step4 - Get the last digits of the number and check
for equality with original number .
Step5 – If equal print automorphic else print not
automorphic.
Step6 - Stop.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 76
Program –
class Program25
{
public static void main(int N)
{
int c=0;
int sq = N*N;
int t = N;
while(t>0)
{
c++;
t=t/10;
}
int lastDigit = (int) (sq%(Math.pow(10, c)));
if(N == lastDigit)
System.out.println(N+ "is an automorphic
number");
else
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 77
Output –
Input
N=25
Output
25 is an automorphic
number.
Shoaib Qureshi
C o m p u t e r S c i e n c e P r o j e c t | 78
Shoaib Qureshi