Documente Academic
Documente Profesional
Documente Cultură
NAME : RAJDIP
CHAKRABORTY
CLASS : X
SECTION : A
ROLL NUMBER : 13
SUBJECT : COMPUTER
CONTENTS:-
Page | 1
Computer project
1. Introduction to Java 3.
2. Body 4-54.
3. Conclusion 55.
Introduction :-
Page | 2
Computer project
A Java code will run on any JVM (Java Virtual Machine). A Java
code is not dependent upon Processor Architecture. A Java
application compiled on 64 bit architecture of any platform will
run on 32 bit system without any issue.
Inventor of Java :-
Page | 3
Computer project
Body:-
Program 1:-
Write a program in Java to display the pattern are as follows :-
*
* * *
* * * * *
* * *
*
Program code:-
Page | 4
Computer project
for(i=1;i<=5;i+=2)
for(m=1;m<=k;m++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println();
k--;
k+=2;
for(i=3;i>=1;i-=2)
for(m=1;m<=k;m++)
System.out.print(" ");
Page | 5
Computer project
for(j=1;j<=i;j++)
System.out.print("*");
System.out.println();
k++;
Variable description:-
Page | 6
Computer project
Output : -
Program 2:-
Write a program in Java to display the pattern as follows :-
abcdcba
abc cba
ab ba
a a
ab ba
Page | 7
Computer project
abc cba
abcdcba
Program code:-
for(i=4;i>=1;i--)
n=97;
for(j=0;j<i;j++)
System.out.print((char)(n+j));
System.out.print(j1);
j1=j1+" ";
Page | 8
Computer project
for(k=i-1;k>=0;k--)
k=k-1;
System.out.print((char)(n+k));
System.out.print("\n");
if(i==4)
j1=" ";
for(i=2;i<=4;i++)
n=97;
for(j=0;j<i;j++)
System.out.print((char)(n+j));
if(i<4)
System.out.print(j2);
Page | 9
Computer project
j2=" ";
for(k=i-1;k>=0;k--)
k=k-1;
System.out.print((char)(n+k));
System.out.print("\n");
Variable description:-
Page | 10
Computer project
Output : -
Program 3:-
Write a program in Java that implements interest class which
stores three variables rate, time and principal. Calculate the Simple
Interest. [use Function calling]:-
Program code:-
import java.util.*;
Page | 11
Computer project
principal=ss.nextDouble();
rate=ss.nextDouble();
time=ss.nextDouble();
ob.simpleInterest(principal,rate,time);
double si;
si=(p*t*r)/100;
Page | 12
Computer project
Variable description:-
Output : -
Page | 13
Computer project
Program 4:-
Write a program in Java that invokes method toWord() that
receives a single digit number and displays it in words:-
Program code:-
import java.util.*;
int d;
Page | 14
Computer project
d=ss.nextInt();
ob.toWord(d);
switch(digi)
case 1: System.out.println("ONE");
break;
case 2: System.out.println("TWO");
break;
case 3: System.out.println("THREE");
break;
case 4: System.out.println("FOUR");
break;
case 5: System.out.println("FIVE");
break;
case 6: System.out.println("SIX");
break;
Page | 15
Computer project
case 7: System.out.println("SEVEN");
break;
case 8: System.out.println("EIGHT");
break;
case 9: System.out.println("NINE");
break;
Variable description:-
Output : -
Page | 16
Computer project
Program 5:-
Write a program in Java to display the amount in rupees in terms
of notes of different denominations:-
Program code:-
import java.util.*;
int a,b,c,d,f,g,h,n,i,j,w;
n=ss.nextInt();
Page | 17
Computer project
w=n/2000;
n=n%2000;
a=n/500;
n=n%500;
b=n/200;
n=n%200;
c=n/100;
n=n%100;
d=n/50;
n=n%50;
f=n/20;
n=n%20;
g=n/10;
Page | 18
Computer project
n=n%10;
h=n/5;
n=n%5;
i=n/2;
n=n%2;
Variable description:-
Page | 19
Computer project
Output : -
Page | 20
Computer project
Program 6:-
Write a program in Java that implements a rectangle class. The
rectangle has fields length, breadth, area and perimeter. It has
methods to obtain the values and length and breadth to calculate
area and perimeter. Invoke methods of rectangle class using main
function:-
Program code:-
import java.util.*;
double length,breadth,area,perimeter;
Page | 21
Computer project
void getValues()
length=ss.nextDouble();
breadth=ss.nextDouble();
calculate();
void calculate()
area=length*breadth;
perimeter=2*(length+breadth);
void display()
Page | 22
Computer project
ob.getValues();
ob.display();
Variable description:-
Page | 23
Computer project
Output : -
Program 7:-
n is a perfect number if the sum of all factors of the number is the
sum excluding itself is n. Define a class called Number Problems
which has the following functions – int sumOfFactors(int n) which
returns sum of all the number n except itself. booleani Perfect(int
n) which returns true if number n is perfect and false otherwisw.
voidperfectNO(int lim) which first prints out all the perfect number
less than lim.:-
Program code:-
Page | 24
Computer project
import java.util.*;
int sumOfFactors(int n)
int i,s=0;
for(i=1;i<n;i++)
if(n%i==0)
s=s+i;
return s;
boolean isPerfect(int n)
if(sumOfFactors(n)==n)
return true;
else
return false;
Page | 25
Computer project
int k,j,c=1;
for(k=1;k<lim;k++)
if(isPerfect(k))
System.out.print(+k+" = ");
for(j=1;j<k;j++)
if(k%j==0)
System.out.print(+j+" ");
System.out.println();
System.out.println();
Page | 26
Computer project
int lim;
lim=ss.nextInt();
ob.perfectNo(lim);
Variable description:-
Page | 27
Computer project
Output : -
Program 8:-
Write a menu-driven program to perform – (i) Accept a number and
convert to its binary equivalent & (ii) Accept a binary number and
convert to its decimal form:-
Program code:-
import java.util.*;
Page | 28
Computer project
int ch;
long d,b,s=0,s1=0,c=0,p=0,e=0;
ch=ss.nextInt();
switch(ch)
d=ss.nextLong();
while(d>0)
c=d%2;
s=s*10+c;
d=d/2;
Page | 29
Computer project
while(s>0)
c=s%10;
s1=s1*10+c;
s=s/10;
break;
b=ss.nextLong();
while(b>0)
c=b%10;
e=e+c*(long)Math.pow(2,p);
b=b/10;
p++;
break;
Page | 30
Computer project
Variable description:-
Output : -
Page | 31
Computer project
Program 9:-
Write a program in Java to implement Bubble Sorting:-
Program code:-
import java.util.*;
int i,j,t=0;
for(i=0;i<5;i++)
m[i] = ss.nextInt();
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
Page | 32
Computer project
if(m[i]>m[j])
t = m[i];
m[i] = m[j];
m[j] = t;
for(i=0;i<5;i++)
System.out.println(m[i]);
Variable description:-
Page | 33
Computer project
Output : -
Program 10:-
Write a program in Java to implement Selection Sorting:-
Program code:-
import java.util.*;
Page | 34
Computer project
int i,j,t=0,min=0;
for(i=0;i<5;i++)
m[i] = ss.nextInt();
for(i=0;i<4;i++)
min = i;
for(j=i+1;j<5;j++)
if(m[i]>m[j])
min = j;
t = m[i];
m[i] = m[min];
m[min] = t;
Page | 35
Computer project
for(i=0;i<5;i++)
System.out.println(m[i]);
Variable description:-
Page | 36
Computer project
Output : -
Program 11:-
Page | 37
Computer project
Program code:-
import java.util.*;
int a,b,c=0,ch;
ob.a=ss.nextInt();
ob.b=ss.nextInt();
System.out.println("1. ADDITION");
System.out.println("2. SUBTRACTION");
System.out.println("3. MULTIPLICATION");
Page | 38
Computer project
ob.ch=ss.nextInt();
switch(ob.ch)
case 1: ob.addition();
break;
case 2: ob.subtraction();
break;
case 3: ob.multiplication();
break;
case 4: ob.integerDivision();
break;
case 5: ob.integerMinus();
break;
void addition()
Page | 39
Computer project
c=a+b;
System.out.println("ADDITION IS : "+c);
void subtraction()
if(a>b)
c=a-b;
else
c=b-a;
System.out.println("SUBTRACTION IS : "+c);
void multiplication()
c=a*b;
System.out.println("MULTIPLICATION IS : "+c);
void integerDivision()
if(a>b)
Page | 40
Computer project
c=a/b;
else
c=b/a;
void integerMinus()
c=a-b;
Variable description:-
choice.
Output : -
Program 12:-
Twin prime numbers are prime numbers where difference is two.
Eq- 3,5 5,7 11,13 17,14, etc. :
Define a class which takes an integer argument and print all the
twin numbers :-
Program code:-
import java.util.*;
Page | 42
Computer project
int lim,n,i,j,num,c=0,k=0,m,p=0;
lim=ss.nextInt();
for(i=1;i<lim-2;i++)
num=i+2;
for(j=1;j<=i;j++)
c=i%j;
if(c==0)
k++;
for(m=1;m<=num;m++)
c=num%m;
Page | 43
Computer project
if(c==0)
p++;
k=0;
p=0;
Variable description:-
Page | 44
Computer project
Output : -
Program 13:-
Write a program in Java to input any Roman Number and the same
in decimal format using User Defined Function:-
Page | 45
Computer project
Program code:-
import java.io.*;
int x;
ro=br.readLine();
String ron=ro.toUpperCase();
char v=ron.charAt(x);
case 'M':
Page | 46
Computer project
d+=1000;
break;
case 'D':
d+=500;
break;
case 'C':
d+=100;
break;
case 'L':
d+=50;
break;
case 'X':
d+=10;
break;
case 'V':
Page | 47
Computer project
d+=5;
break;
case 'I':
d+=1;
break;
if(ron.contains("IV"))
d-=2;
if(ron.contains("IX"))
d-=2;
if(ron.contains("XL"))
d-=20;
Page | 48
Computer project
if(ron.contains("XC"))
d-=20;
if(ron.contains("CD"))
d-=200;
if(ron.contains("CM"))
d-=200;
Variable description:-
by the users.
Output : -
Program 14:-
Write a program to accept a string. Convert the string to
uppercase. Count the number of double letter sequences that exist
in the string:-
Program code:-
import java.io.*;
public class DoubleLetter
{
public static void main(String args[])throws IOException
Page | 50
Computer project
{
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String s,u;
System.out.println("Enter a String:");
s=br.readLine();
u = s.toUpperCase();
int i,p=0;
for (i=0;i<(u.length()-1);i++)
{
if ((u.charAt(i))==u.charAt(i+1))
{
p++;
}
}
System.out.println("The string in upper case : " + u);
System.out.println("Number of double letter sequences in the string : " + p);
}
}
Variable description:-
Page | 51
Computer project
Output : -
Program 15:-
Write a program in Java to store the names, address and telephone
numbers of “N” number of students. Process the data in such a way
that the output appears in alphabetical order under appropriate
headings as given:-
Program code:-
import java.io.*;
public class students
{
public static void main(String args[]) throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int lim;
System.out.println("Enter the number of students : ");
lim=Integer.parseInt(br.readLine());
String name[]=new String[lim];
Page | 52
Computer project
Page | 53
Computer project
}
}
}
System.out.println("Name\t\t\tAddress\t\t\tTelephone No.");
System.out.println("====\t\t\t=======\t\t\t=============");
System.out.println();
for(i=0;i<lim;i++)
{
System.out.print(name[i]+"\t\t"+add[i]+"\t\t"+tel[i]);
System.out.println();
}
}
}
Variable description:-
Page | 54
Computer project
Output : -
CONCLUSION
As with any programming language, Java is a script with
advantages and disadvantages.Java is a general use
programming language.It can,with time and energy,do
just about anything with a decent degree of
efficiency.But if the user is in hurry ,then other
languages are better.The syntax of Java is arguably
simpler than other C derivatives.The Java library is well-
written.Java implements finalization and cleanup of
objects without the need for destructors.It is also
portable to other systems.
Page | 55
Computer project
Page | 56