You are on page 1of 18

qwertyuiopasdfghjklzxcvbnmqwertyui

Page 1 of 18

opasdfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmqwer
COMPUTER
tyuiopasdfghjklzxcvbnmqwertyuiopas

PROJECT
dfghjklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbnmq
FILE
wertyuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopasdfghj
<Name>
klzxcvbnmqwertyuiopasdfghjklzxcvbn
<Class>
mqwertyuiopasdfghjklzxcvbnmqwerty
<Roll Number>
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmrty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
Page 2 of 18

Personal
Memo
Name:
Class:
Roll no.:
Subject:
Subject Teacher:
Guardian Teacher:
Page 3 of 18

Acknowledge
ment
“One’s put to work and one’s put a guide because a voyage is aimless
without a key and education is incomplete without a guide.”

This project was given by my Computer teacher <Name> sir


and I am thankful for his guidance. I put forward my sincere thanks
to my mother, <Name> for her valuable suggestions. I am also
thankful to <Name> for their contribution and support in making
this project. I put forward my special thanks to my friends and other
family members.
Page 4 of 18

Suggestions and comments from teachers and readers are welcome


so that I may be able to make necessary amendments for
improvement in future.

<Name>
<Class>

Contents
Serial Program Page No. Sign Remarks
No.
1. Fantastic Number 5
2. String Fibonacci 8
3. Happy Number 12
4. Sorting/Searching 17
5. ISBN Number 24
6. Sum of Numbers 28
7. Transpose of Array 31
8. Date Based Program 35
9. Palindromic words 38
10. Vowels & 42
Consonants
11. File Creation 46
12. Logic Based Program 49
13. Unit Matrix 52
14. Object Passing 56
Page 5 of 18

15. Stack 59
16. Recursion 64
17. Currency Denomination 67
18. Inheritance 70
19. Linked List 75
20. Sequential Series 78
21. Prime Pattern 82
22. Recursion in Array 85
23. String Based 88
24. Phone Numbers 91
25. Primorial Number 94

PROGRAM 1

Write a program in java to print all three-digit fantastic numbers. A fantastic number is a
number which when multiplied three times and the numbers thus formed result in
formation of a new number as shown below. This number has no repetition of digits and
all digits from one to nine occur (in any sequence).

Example:

Suppose number is 327 then,

327*1= 327

327*2=654

327*3=981

n=327654981

(Here in the number n there is no repetition of digits and all digits from 1 to 9 are
present)

ALGORITHM

Step 1: Start

Step 2: for(int j=100; j<=999; j increases by 1)


Page 6 of 18

Step 3: int f:= 0, p:=1

String num=”” (initializing num with null)

Step 4: for(int i=1; i<=3; i++)

Step 4: p:=j*I;

Step 5: num: num+p

[end of Step 4 for loop]

Step 6: for(char c=’1’; c<=’9’; c increases by 1)

(checking whether all digits from 1 to 9 are present)

Step 7: if(num.indexOf(c)<0)

Step 8: Flag variable f=1

(checking whether the number is fantastic number or not)

[end of Step 6 for loop]

Step 9: if (num.length()==9 and f==0)

Step 10: Print j+ “ “+num+” “+”Fantastic

[End of Step 2 for loop]

Step 11: Stop

PROGRAM CODE

public class fantastic

public void main()

for(int j=100; j<=999; j++)

{
Page 7 of 18

int f=0, p=1;

String num="";

for(int i=1; i<=3; i++)

p=j*i;

num=num+p;

for(char c='1'; c<='9'; c++)

if(num.indexOf(c)<0)

f=1;

if(num.length()==9&&f==0)

System.out.println(j+" "+num+" "+"Fantastic");

VARIABLE DESCRIPTION

OUTPUT
Page 8 of 18
Page 9 of 18

PROGRAM 2

A sequence of Fibonacci strings is generated as follows:

S0=”a”, S1=”b”, Sn=S(n-1)+S(n-2) where ‘+’ denotes concatenation. Thus the sequence
is : a, b, ba, bab, babba, babbabab, …………n terms.

Design a class FiboString to generate fibonnaci strings. Some of the members of the
class are given below:

Class name : FiboString

Data Members/ Instance Variable:

x : to store the first string

y : to strore the second string

z : to store the concatenation of the

previous two strings

n : to store the number of terms

Member functions/ methods:

FiboString() : constructor to assign x=”a”, y=”b”, and z=”ba”

void accept() : to accept the number of terms ‘n’

void generate() : to generate and print the fibonnaci strings.

the sum of (‘+’ i.e., concatenation) first two

strings is the third string. Eg. “a” is first string,

“b” is second string then third string will be

“ba”, and fourth string will be “bab” and so on.

Specify the class FiboString, giving details of the constructor(), void accept(), and
void generate(). Define the main() function to create an object and call the functions
accordingly to enable the task.
Page 10 of 18

ALGORITHM

Step1: Start

Step 2: Read String x, y, z

int n

constructor FiboString()

Step 3: x:=“a”

Step 4: y:=“b”

Step 5: z:=“ba”

void accept()

Step 6: Create an object (say ob) to input data from the user

Step 7: Print “ENTER NUMBER OF TERMS”

Step 8: Get input from the user (say in variable n)

void generate()

Step 9: Read int i

Step 10: Print (x+” “ +y+” “+” “)

Step 11: for (i=3; i<=n; I increases by 1)

Step 12: z:= y+x

Step 13: x:=y

Step 14: y:=z

Step 15: Print z+ “ “

[End of Step 11 for loop]

void main()

Step 16: Create the object of the class (say obj) of FiboString

Step 17: invoke the function accept()

Step 18: invoke the function generate()

Step 19: Stop


Page 11 of 18

PROGRAM CODE

import java.io.*;

public class FiboString

String x,y,z;

int n;

public FiboString()

x="a";

y="b";

z="ba";

void accept()throws IOException

DataInputStream ob= new DataInputStream(System.in);

System.out.println("ENTER NUMBER OF TERMS ");

n=Integer.parseInt(ob.readLine());

void generate()

int i;

System.out.print(x+" "+y+" "+" ");

for(i=3; i<=n; i++)

{
Page 12 of 18

z=y+x;

x=y;

y=z;

System.out.print(z+" ");

void main() throws IOException

FiboString obj=new FiboString();

obj.accept();

obj.generate();

VARIABLE DESCRIPTION

Serial No. Variable Type Purpose


1. x String Used to store first string
2. y String Used to store second string
3. z String Used to store concatenated string
4. n int Input number of terms in series
5. i int Loop control variable

OUTPUT
Page 13 of 18

PROGRAM 3

Write a program in java to check whether a number entered by user is happy


number or not. A happy number is a number in which the eventual sum of the
squares of the digits of the number is equal to one.

Example: 28 = (2)2+ (8)2

= 4 + 64 = 68

68 = (6)2+ (8)2

= 36 + 64 = 100

100 = (1)2+(0)2+(0)2

= 1+0+0 = 1

Hence, 28 is a happy number.

Example: 12 = (1)2+(2)2

= 1+ 4 = 5

Hence, 12 is not a happy number.

Design functions as per your requirement and use recursive technique in at least
one of the function designed by you. Also define main() function to create an object
and call the methods to check for happy number.

ALGORITHM

Step 1: Start

Step 2:Read int n, s,d

Step 3: Create an object (say ob) to input data from the user

Constructor Happy()

Step 4: Initialize n with 0

getnum(int nn)

Step 5: Initialize n with nn

sum_sq_digits(int x) // Recursive function

Step 6: if(x>0)
Page 14 of 18

Step 7: d:=x mod 10

Step 8: s:=s+d*d

Step 9: x:=x/10

Step 19: Call the recursive function sum_sq_digits(x)

Step 20: else

return s

void ishappy()

Step 20: Read int a

Step 21: Repeat Step 22 to Step 23 while(n>9)

Step 22: s:=0

(invoke the function sum_sq_digits())

Step 23: n:=sum_sq_digits(n)

[end of Step 21 while loop]

Step 24: if n==1

Step 25: Print “HAPPY NUMBER”

Step 26: else

Print “NOT A HAPPY NUMBER”

void main()

Step 27: Read int num

Step 28: Print “ENTER A NUMBER”

Step 29: Get input from the user (say in variable num)

Step 30: Create an object (say obj) of the class Happy

Step 31: Invoke the function getnum(num)

Step 32: Invoke the function ishappy()

Step 33: Stop


Page 15 of 18

PROGRAM CODE

import java.io.*;

public class Happy

int n, s, d;

DataInputStream ob=new DataInputStream(System.in);

Happy()

n=0;

void getnum(int nn)

n=nn;

int sum_sq_digits(int x)

if(x>0)

d=x%10;

s=s+d*d;

x=x/10;

return(sum_sq_digits(x));

else
Page 16 of 18

return s;

void ishappy()

int a;

while(n>9)

s=0;

n=sum_sq_digits(n);

if(n==1)

System.out.println("HAPPY NUMBER");

else

System.out.println("NOT A HAPPY NUMBER");

void main() throws IOException

int num;

System.out.println("ENTER A NUMBER");

num=Integer.parseInt(ob.readLine());

Happy obj=new Happy();


Page 17 of 18

obj.getnum(num);

obj.ishappy();

VARIABLE DESCRIPTION

Serial No. Variable Type Purpose


1. n int Used to store the number
2. s int Used to store the sum of squares of
digits in the number
3. d int Used to extract the digits from the
number
4. nn int To initialize the instance variable ‘n’
with its legal value
5. num int To input the number from the user

OUTPUT
Page 18 of 18

BUY NOW TO GET YOUR PROJECT FILE DELIVERED IN YOUR


MAILBOX

You might also like