Computer Project
Computer Project
int n;
void accept ()
n=sc.nextInt ();
void compute ()
{
int i, c=0;
if (n%i==0)
c++;
if (c==2)
else
obj.accept ();
obj.compute ();
}
Output=Enter any number
13
Prime number
Enter any number
62
Not a Prime number
Q2=Design a class prime –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Void compute () = to check the number is palindrome or not
Ans=import java.util.*;
class prime
int n;
void accept ()
n=sc.nextInt ();
void compute ()
int b, r, s=0;
b=n;
while (b>0)
r=b%10;
s=s*10+r;
b=b/10;
if (s==n)
else
obj.accept ();
obj.compute ();
}
Output= Enter any number
555
Palindrome number
Enter any number
656
Palindrome number
Q3=Design a class series –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Int fact (int x) = to return the factorial of parameter
Void compute () =to display the sum of all factorial till n
Ans= import java.util.*;
class series
int n;
void accept ()
n=sc.nextInt ();
{
int i, f=1;
f=f*i;
return f;
void compute ()
int i, s=0;
s=s+fact (i);
obj.accept ();
obj.compute ();
Sum is 873
30
Sum is 864159207
Q4=Design a class number –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Int count factor (int x) = to return the total number of factor
Of x
Void compute () = to display all prime number from 1 to n.
Ans= import java.util.*;
class number
int n;
void accept ()
n=sc.nextInt ();
int i, c=0;
if(x%i==0)
c++;
return c;
void compute ()
int i;
if (k==2)
obj.accept ();
obj.compute ();
11
13
Q5=Design a class number –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Int count zero (int x) = to return the frequency of zero digit
Void display () = to check the number is duck number or not
Ans= import java.util.*;
class number
int n;
void accept ()
n=sc.nextInt ();
{
int r, c=0;
while (n>0)
{
r=n%10;
If(r==0)
c++;
x=x/10;
return c;
void display ()
If (k>=1)
else
{
number obj= new number ();
obj.accept ();
obj.display ();
}
Duck number
Q6=Design a class number –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Boolean check prime (int x) = to check whether the
Parameter is prime or not
Int reverse () = to return the reverse of the parameter
Void display () = to check the number is emrip number or
not
Ans= import java.util.*;
class number
int n;
void accept ()
n=sc.nextInt ();
}
boolean check prime (int x)
int i, c=0;
If(x%i==0)
c++;
If(c==2)
return true;
else
return false;
int r, s=0;
while(x>0)
r=x%10;
s=s*10+r;
x=x/10;
}
return s;
void display ()
else
obj.accept ();
obj.display ();
}
Output= Enter any number
13
Emrip number
27
Int n;
void accept ()
n=sc.nextInt ();
int i, c=0;
if(x%i==0)
c++;
if(c==2)
return true;
else
return false;
int r, s=0;
while(x>0)
r=x%10;
s=s*10+r;
x=x/10;
return s;
}
void display ()
obj.accept ();
obj.display ();
}
Output= Enter any number=39
11
13
17
31
37
Q8=Design a class number –
Data member /Instance variable
Int n- to store the number
Member functions
Void accept () = to input the number
Int binary (int x) = to return the binary form
Void display () = to return binary of all number from 1 to n
Ans= import java.util.*;
class number
int n;
void accept ()
n=sc.nextInt ();
{
String s="";
Int r;
While(x>0)
r=x%2;
s=r+s;
x=x/2;
int p= Integer.parseInt(s);
return p;
}
void display ()
obj.accept ();
obj.display ();
int n;
void accept ()
n=sc.nextInt ();
{
If (i<=n)
else
return 0;
void display ()
obj.accept ();
obj.display ();
}
Output= Enter any number
10
Sum is55
Enter any number
59
Sum is1770
Q10=Design a class function –
Data member /Instance variable
Int n, m- to store the number
Member functions
Void accept () = to input the number m and n
Int HCF (int x, int y) =to return the HCF of a parameter
Void display () = to display the HCF and LCM
Ans= import java.util.*;
class function
int n, m;
void accept ()
n=sc.nextInt ();
m=sc.nextInt ();
}
if (a>b)
a=a-b;
else
b=b-a;
return a;
void display ()
}
public static void main (String args [])
obj.display ();
}
}
int i, n;
void input ()
n=sc.nextInt ();
}
If (i<=n)
else
return 1;
void display ()
obj.input ();
obj.display ();
}
Output= Enter any number
8
Product is40320
Enter any number
5
Product is120
Q2=Design a class recursion –
Data member /Instance variable
Int n- to store the number
Member functions
Void input () = to input the number
Int fact (int x) =to return the factorial of parameter using
Recursive technique
Void display () = to display the sum of all factorial till n
Ans= import java.util.*;
class recursion
{
int n;
void input ()
n=sc.nextInt ();
If(x>=1)
else
return 1;
}
void display ()
int i, s=0;
obj.input ();
obj.display ();
}
int n;
void getdata ()
n=sc.nextInt ();
If(x==0)
return 0;
else
void display ()
obj.getdata ();
obj.display ();
}
Output=Enter any number
123
Sum of all digits are 6
Enter any number
5555
Sum of all digits are 20
Q4=Design a class number –
Data member /Instance variable
Int n- to store the number
Member functions
Void getdata () = to input the number
Int countdigit (int x) =to return total number of digits in a
Parameter using recursive technique
Void display () = to check whether the number is dissarium
Number or not
Ans= import java.util.*;
class number
int n;
void getdata ()
n=sc.nextInt ();
}
int countdigit (int x)
If (x==0)
return 0;
else
void display ()
int b=n,r;
double s=0;
while (b>0)
r=b%10;
k--;
b=b/10;
if(s==n)
System .out .println ("Dissarium number");
else
obj.getdata ();
obj.display ();
}
int n;
void accept ()
n=sc.nextInt ();
}
int countzero (int x)
if(x==0)
return 0;
else
if (x% 10 == 0)
else
void display ()
if (k>=1)
else
obj.accept ();
obj.display ();
}
int n;
void accept ()
n=sc.nextInt ();
if (i<=x)
if (x% i== 0)
else
else
return 0;
}
void display ()
if (k==2)
}
public static void main (String args [])
obj.accept ();
obj.display ();
}
int n, a;
void input ()
a= sc.nextInt ();
}
int fact (int x)
If (x>=1)
else
return 1;
If (y>=1)
else
return 1;
void display ()
int i;
double s=0;
obj.input ();
obj.display ();
}
Output = Enter any two number
5
2
Sum is40.0
Enter any two number
12
8
Sum is9692700.0
Q8=Design a class recur –
Data member /Instance variable
Int n- to store the number
Member functions
Void input () = to input the value of n
Int HCF (int a, int b) =to calculate HCF of a number using
Recursive technique
Void display () = to display the HCF
Ans=import java.util.*;
class recur
{
int a, b;
void input ()
{
Scanner sc= new Scanner (System .in);
a= sc.nextInt ();
b= sc.nextInt ();
}
int HCF (int a, int b)
if (b>a)
a=a+b;
b=a-b;
a=a-b;
if (a%b ==0)
return b;
void display ()
obj.display ();
}
}
If(wd.length () <=0)
Return 0;
Return !;
Else
Else
}
Q10=Design a class to check if a program is palindrome or not.
class palin
{
String s;
String accept ()
s= sc.next ();
Return true;
Else
{
Return false;
}}}
Programs from File Handling
Q1=Write a program in java and create a text file about me and
write the information in the file
Ans=import java.util.*;
class abc
{
public static void main (String args [])
{
FileWriter FW = new FileWriter (“about me”);
BufferedWriter BR = new BufferedWriter (FW);
PrintWriter PW = new PrintWriter (BR);
PW.println (“Name = Riya Raturi”);
PW.println (“Class= 11; Section = A”);
PW.println (“Hobby = Book Reading”);
BR.close ();
PW.close ();
}
}
Q2=Write a program to input a file name from user and print
the file data and also print total number of characters in a file.
Ans=import java.util*;
Import java.io*;
class filename
{
public static void main (String args []) throws IOException
{
String FN;
Scanner sc= new Scanner (System.in)
System.out.println (“Enter file name”);
FN= sc.nextline ();
int ct=0;
FileReader FR = new FileReader (FN);
BufferedReader BR = new BufferedReader (FR);
String line= BR.readLine ();
while (line! = null)
{
System.out.println (line);
ct++= lineLength ();
Line = BR.readLine ();
}
System.out.println (“Total number of characters”+ct);
BR.close ();
FR.close ();
}
}
Q3=Write a program and input a file name from user and print
each line along with number of words in the line and at the end
also print total number of words.
Ans= import java.util*;
Import java.io*;
class program
{
public static void main (String args []) throws IOException
{
String FN;
Scanner sc= new Scanner (System.in)
System.out.println (“Enter file name”);
FN= sc.nextline ();
FileReader FR = new FileReader (FN);
BufferedReader BR = new BufferedReader (FR);
String line= BR.readLine ();
while (line! = null)
{
int c= 0;
For (int i=0; i< line.length (); i++)
{
If (line.charAt (i) ==’ ‘)
C++;
}
System.out.println (line+ /+ “Number of words” + (c+ 1));
ct= ct+ (c+1);
Line = BR.readLine ();
}
System.out.println (“Total number of words”+ct);
BR.close ();
FR.close ();
}
}
Q4=Write a program and write class test marks in a file T marks.
Input subject name and marks from user
Ans= import java.util*;
Import java.io*;
class testmarks
{
public static void main (String args []) throws IOException
{
FileOutputStream fos= new FileOutputStream (“ct marks.
data”);
DataOutputStream dos= new DataOutputStream (fos);
Scanner sc= new Scanner (System.in);
String subname;
Int submo;
for (i=0; i<6; i++)
{
System.out.println (“Enter subject name”);
subname= sc.nextline ();
System.out.println (“Enter marks”);
submo= sc.nextInt ();
dos.writeUTF (subname);
dos.writeInt (submo);
}
dos.close ();
fos.close ();
}
}
Q5=Write a program and input n employees detail from user
and write in a file emp.dat and details like employees basic
salary, age, id.
Ans= import java.util*;
Import java.io*;
class testmarks
{
public static void main (String args []) throws IOException
{
FileOutputStream fos= new FileOutputStream (“detail. dat”);
DataOutputStream dos= new DataOutputStream (fos);
Scanner sc= new Scanner (System.in);
String name, gender;
Int id, age, salary;
for (i=0; i<=5; i++)
{
System.out.println (“Enter name”);
name= sc.nextline ();
}
catch (“eof Exception eo”)
{
eof= true;
}
}
dis.close ();
fis.close ();
}
}
Q8=Write a program to count and print only palindrome words.
Ans= = import java.util*;
Import java.io*;
class program
{
public static void main (String args []) throws IOException
{
Scanner sc= new Scanner (System.in);
String s, wd, rwd;
int c=0;
System.out.println (“Enter any sentence”);
s=sc.nextLine ();
String Tokenizer st= new String Tokenizer(s);
int ct= st.countTokens ();
for (i=0; i<ct; i++)
{
wd= st. countTokens ();
rwd= new StringBuffered (wd). reverse (). toString ();
if (wd.equal (rwd))
{
System.out.println (wd);
c++;
}
}
System.out.println (“Number of palindrome words”+c);
}
}
Q9=Write a program to input a string and print the longest
word of the string
Ans= import java.util*;
Import java.io*;
class program
{
public static void main (String args []) throws IOException
{
Scanner sc= new Scanner (System.in);
String s, wd, rwd;
int c=0;
System.out.println (“Enter any sentence”);
s=sc.nextLine ();
String Tokenizer st= new String Tokenizer(s);
int ct= st.countToken ();
rwd=””;
for (i=0; i<ct; i++)
{
wd= st. countToken ();
if (wd.length () > rwd. length ())
rwd=wd;
}
System.out.println (“Longest word=”+rwd);
}
}
Q10=Write a program to input a string count and print total
number of vowels and number of palindrome words also print
the palindrome words.
Ans= import java.util*;
Import java.io*;
class text
{
String str;
public text ();
{
str=””;
}
public void input ()
{
Scanner sc= new Scanner (System.in);
System.out.println (“Enter any sentence”);
str=sc.nextLine ();
}
public booleanisPalin (String wd)
{
If (wd.length () <=1)
return true;
else
{
If (wd.charAt (0)! =wd.charAt (wd.length () - 1))
return false;
returnisPalin (wd.substring (1, wd.length ()-1+””) ;
}
}
public int count vol (String wd)
{
if (wd.length () <=0)
return 0;
else if (wd.length () == 1)
{
if (“AEIOUaeiou”. indexOf (wd.charAt (0)>=0));
return!;
else
If (“AEIOUaeiou”. indexOf (wd.charAt (0)>=0));
return (1+ count (wd.substring (1)));
else
return (0+ count (wd.substring (1)));
}
}
public void show ()
{
Int nv= countvol(s+r);
System.out.println (“Number of vowels=” +nv);
String Tokenizer s + k= new String Tokenizer(s+r);
int ct= s+k.countToken ();
String w;
for (i=1; i<=ct; i++)
{
w= s+ k. nextToken ();
if (isPalin (w))
System.out.println (w);
}
}
public static void main (String args [])
{
text obj= new text ();
obj. Input ();
obj.show ();
}
}
Conclusion
In the end, I would like to say that this is a very interesting
project. I have gained a lot of knowledge about this topic. I am
also very grateful to my friends, parents and teachers for the
valuable and precious support which they all have provided me.
Bibliography
I have used the following sources for this project.
(1)Computer Science with java ISC
(2)Knowledge Boat