Java Prog
Java Prog
Java Prog
Program :
class prog1
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
if((n%3)==0)
{
if((n%2)!=0)
System.out.println("The number is divisible by 3 but not divisible 2");
else
System.out.println("The number is divisible by 3 and 2");
}
else
System.out.println("The number is not divisible by 3");
}
}
OUTPUT :-
C:\Java>java prog1 3
The number is divisible by 3 but not divisible 2
C:\Java>java prog1 30
The number is divisible by 3 and 2
C:\Java>java prog1 2
The number is not divisible by 3
C:\Java>
1
ASSIGNMENT::--2
Problem Statement: Write a program to check a number prime or not.
Program :
class prog2
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
int flag=0;
for(int i=2;i<=Math.sqrt(n);i++)
{
int m=n%i;
if(m==0)
{
flag=1;
System.out.println(“The number is not prime”);
break;
}
}
if(flag==0)
System.out.println(“The number is prime”);
}
}
OUTPUT :-
C:\Java>javac prog2.java
C:\Java>java prog2 30
The number is not prime
C:\Java>java prog2 21
The number is not prime
C:\Java>java prog2 41
The number is prime
C:\Java>
2
ASSIGNMENT::--3
Problem Statement: Write a program to convert decimal to binary.
Program :
class prog3
{
public static void main(String args[])
{
int n1,r,i,b=1,bi=0;
int n=Integer.parseInt(args[0]);
n1=n;
while(n!=0)
{
r=n%2;
b=10*b+r;
n=n/2;
}
int b1=b;
while(b!=0)
{
r=b%10;
bi=10*bi+r;
b=b/10;
}
bi=bi/10;
System.out.println(“Decimal =”+n1);
System.out.println(“Binary =”+bi);
}
}
OUTPUT :-
C:\Java>javac prog3.java
C:\Java>java prog3 8
Decimal =8
Binary =1000
C:\Java>java prog3 21
Decimal =21
Binary =10101
C:\Java>
3
ASSIGNMENT::--4
Problem Statement: Write a program to determine multiplication
of two Matrices
Program :
import java.util.*;
class Matrix
{
private int row,col;
private int[][] x;
public Matrix()
{
row=0;
col=0;
x=new int[10][10];
}
4
for(i=0;i<row;i++)
{
System.out.print(“\t”);
for(j=0;j<col;j++)
{
System.out.print(“\t”+x[i][j]);
}
System.out.println();
}
}
public Matrix mul(Matrix a)
{
int i,j,k;
Matrix t;
t=new Matrix();
t.row=row;
t.col=a.col;
for(i=0;i<t.row;i++)
{
for(j=0;j<t.col;j++)
{
t.x[i][j]=0
for(k=0;k<col;k++)
t.x[i][j]=t.x[i][j]+x[i][k]*a.x[k][j];
}
}
return t;
}
}
class MatrixTest
{
public static void main(String[] args)
{
Int r1,c1,r2,c2;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the row and col of 1st matrix: ”);
r1=sc.nextInt();
c1=sc.nextInt();
System.out.println(“Enter the row and col of 2nd matrix: ”);
r2=sc.nextInt();
c2=sc.nextInt();
if(c1==r2)
{
Matrix a=new Matrix();
a.read(r1,c1);
Matrix b=new Matrix();
b.read(r2,c2);
Matrix c=new Matrix();
5
c=a.mul(b);
System.out.println(“The 1 st matrix is: ”);
a.display();
System.out.println(“The 2nd matrix is: ”);
d.display();
System.out.println(“The resultant matrix is: ”);
c.display();
}
else
System.out.println(“Matrix multiplication is not possible.”);
}
}
OUTPUT :-
6
ASSIGNMENT::--5
Problem Statement: Write a program to short a list of string alphabetic
order.
Program :
class prog5
{
public static void main(String args[])
{
int n=args.length;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(args[j].compareTo(args[i])>0)
{
String temp=args[i];
args[i]=args[j];
args[j]=temp;
}
}
}
for(int i=0;i<n;i++)
System.out.println(args[i]);
}
}
OUTPUT :-
C:\Java>javac prog5.java
C:\Java>
7
ASSIGNMENT::--6
Problem Statement: Write a program to calculate the area in square meter
to accept radius in meter as user input the command line.
Program :
class prog6
{
public static void main(String args[])
{
int r;
double area;
r=Integer.parseInt(args[0]);
area=3.14*r*r;
OUTPUT :-
C:\Java>java prog6 10
area of a circle 314.0
C:\Java>javac prog6.java
C:\Java>java prog6 10
Radius of a circle is 10
Area of a circle is 314.0
C:\Java>java prog6 67
Radius of a circle is 67
Area of a circle is 14095.46
C:\Java>
8
ASSIGNMENT::--7
Problem Statement: Write a program to check a number is Armstrong or not
in general case.
Program :
class prog7
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
int n2=0,r,n1=n;
while(n!=0)
{
r=n%10;
n2=n2+(r*r*r);
n=n/10;
}
if(n1==n2)
System.out.println(“The number is amstrong number”);
else
System.out.println(“The number is not amstrong number”);
}
}
OUTPUT :-
C:\Java>javac prog7.java
C:\Java>java prog7 10
The number is not amstrong number
C:\Java>
9
ASSIGNMENT::--8
Problem Statement: Write a program to calculate a Fibonacci number
without creating an object using another class.
Program :
class generate
{
static int gen(int x,int y)
{
return(x+y);
}
class prog8
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
int a[]=new int[100];
a[0]=0;
a[1]=1;
System.out.println();
System.out.println(“The fibbonacci series:-”);
for(int i=2;i<n;i++)
{
int f=generate.gen(a[i-1],a[i-2]);
a[i]=f;
}
for(int i=0;i<n;i++);
System.out.print(“ ”+a[i]);
System.out.println();
}
}
OUTPUT :-
C:\Java>javac prog8.java
C:\Java>java prog8 15
10
ASSIGNMENT::--9
Program :
class MethodLoad
{
int a,b,c;
double r;
MethodLoad()
{
a=0;
b=0;
c=0;
r=0;
System.out.println(“Method Overloading”);
}
int volume(int p,int q,int r)
{
return p*q*r;
}
int volume(int x)
{
return x*x*x;
}
double volume(double r1)
{
return((4*3.14159*r1*r1*r1)/3);
}
}
class prog9
{
public static void main(String args[])
{
MethodLoad m=new MethodLoad();
System.out.println(“Volume of a Rectangular Bar is:”+m.volume(10,15,20));
System.out.println(“Volume of a Squareshape Bar is:”+m.volume(20));
System.out.println(“Volume of a Sphere is:”+m.volume(10.0));
}
}
11
OUTPUT :-
C:\Java>javac prog9.java
C:\Java>java prog9
Method Overloading
Volume of a Rectangular Bar is:3000
Volume of a Squareshape Bar is:8000
Volume of a Sphere is:4188.786666666667
C:\Java>
12
ASSIGNMENT::--10
Problem Statement: Write a program to calculate the volume of different
shape using Constructor Overloading.
Program :
class ConLoad
{
int a,b,c;
double r;
ConLoad()
{
System.out.println(“Constructor Overloading”);
}
ConLoad(int p,int q,int r)
{
a=p;
b=q;
c=r;
System.out.println(“Volume of aRectangular Bar is: ”+(a*b*c));
}
ConLoad(int x)
{
a=x;
System.out.println(“Volume of a Squareshape Bar is: ”+(a*a*a));
}
ConLoad(double r1)
{
r=r1;
System.out.println(“Volume of a Sphere is: ”+((4*3.14159*r*r*r)/3));
}
}
class prog10
{
public static void main(String args[])
{
ConLoad c=new ConLoad();
ConLoad c1=new ConLoad(10,15,20);
ConLoad c2=new ConLoad(20);
ConLoad c3=new ConLoad(10.0);
}
}
13
OUTPUT :-
C:\Java>javac prog10.java
C:\Java>java prog10
Constructor Overloading
Volume of a Rectangular Bar is:3000
Volume of a Squareshape Bar is:8000
Volume of a Sphere is:4188.786666666667
C:\Java>
14
ASSIGNMENT::--11
Problem Statement: Write a program to calculate the Area of different shape
using Interface.
Program :
interface face
{
int area1(int p,int q);
int area1(int y);
double area1(double r1);
}
class Area
{
int a,b;
double r;
Area()
{
a=0; b=0; r=0;
}
int area1(int p,int q)
{
return p*q;
}
int area1(int x)
{
return x*x;
}
double area1(double r1)
{
return (3.14159*r1*r1);
}
}
class prog11
{
public static void main(String args[])
{
Area a=new Area();
System.out.println(“Area of a Rectangle is:”+a.area1(10,15));
System.out.println(“Area of a Square is:”+a.area1(20));
System.out.println(“Area of a Circle is:”+a.area1(10.0));
}
}
15
OUTPUT :-
C:\Java>javac prog11.java
C:\Java>java prog11
Area of a Rectangle is:150
Area of a Square is:400
Area of a Circle is:314.159
C:\Java>
16
ASSIGNMENT::--12
Problem Statement: Write a program using Method overriding.
Program :
class Super
{
int x;
Super(int x)
{
this.x=x;
}
void display()
{
System.out.println(“Super x = ”+x);
}
}
class prog12
{
public static void main(String args[])
{
Sub s1 = new Sub(100,200);
s1.display();
}
}
17
OUTPUT :-
C:\Java>javac prog12.java
C:\Java>java prog12
Super x = 100
Sub y = 200
C:\Java>
18
ASSIGNMENT::--13
Problem Statement: Write a program using Treading.
Program :
19
}
}
System.out.println(“Exit From C”);
}
}
class prog13
{
public static void main(String args[])
{
A treadA = new A();
B treadB = new B();
C treadC = new C();
OUTPUT :-
C:\Java>javac prog13.java
Note: prog13.java uses or overrides a deprecated API.
Note: Recompile with –deprecation for details.
C:\Java>java prog13
Start Tread A
Start Tread B
Start Tread C
End of Main Tread
From Thread A : i = 1
From Thread B : j = 1
From Thread C : k = 1
From Thread A : i = 2
From Thread B : j = 2
From Thread A : i = 3
20
From Thread A : i = 4
From Thread A : i = 5
Exit From A
From Thread B : j = 3
From Thread C : k= 2
From Thread C : k= 3
From Thread C : k= 4
From Thread C : k= 5
Exit From C
C:\Java>javac prog13.java
Note: prog13.java uses or overrides a deprecated API.
Note: Recompile with –deprecation for details.
C:\Java>java prog13
Start Tread A
Start Tread B
Start Tread C
From Thread B : j = 1
From Thread B : j = 2
From Thread B : j = 3
End of Main Tread
From Thread A : i = 1
From Thread A : i = 2
From Thread A : i = 3
From Thread C : k = 1
From Thread A : i = 4
From Thread A : i = 5
Exit From A
From Thread C : k = 2
From Thread C : k = 3
From Thread C : k = 4
From Thread C : k = 5
Exit From C
21
ASSIGNMENT::--14
Problem Statement:
Program :
class ScreenDis
{
public static void main(String args[])
{
int i,j;
System.out.println("\nScreen Display Done: ");
System.out.println();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(" "+j);
}
System.out.println();
}
}
}
OUTPUT :-
C:\Java>javac ScreenDis.java
C:\Java>java ScreenDis
1
1 2
1 2 3
1 2 3 4
22
ASSIGNMENT::--15
Problem Statement:
Write a Java Program to Print The Following Tringle:
1
01
101
0101
Program :
class Tringle
{
public static void main(String args[])
{
int i,j,k,p;
System.out.println("\nScreen Display Done: ");
System.out.println();
for(i=1;i<=4;i++)
{
p=i;
for(k=4;k>=i;k--)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print(p%2+" ");
p--;
}
System.out.println();
}
}
}
OUTPUT :-
C:\Java>javac Tringle.java
C:\Java>java Tringle
1
0 1
1 0 1
23
0 1 0 1
ASSIGNMENT::--16
Problem Statement:Write a Java Program to Find The Sum of All Prime
Numbers Between n to m Where n<m And n,m <-
Natural Numbers.
Program :
import java.io.DataInputStream;
class Sum_of_Prime
{
public static void main(String args[])
{
int n=0,m=0,i,j,k=0,sum=0;
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.println("\nEnter The Range to Find Sum of Prime Numbers: ");
n=Integer.parseInt(in.readLine());
m=Integer.parseInt(in.readLine());
}
catch(Exception e)
{
System.out.println("Wrong Input");
}
for(i=n;i<=m;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
k++;
break;
}
}
if(k==0)
sum=sum+i;
k=0;
}
System.out.println("\nThe Sum of All Prime Numbers Between "+n+" to "+m+" is:
"+sum);
}
}
24
OUTPUT :-
C:\Java>javac Sum_of_Prime.java
C:\Java>java Sum_of_Prime
C:\Java>java Sum_of_Prime
The Sum of All Prime Numbers Between 100 to 500 is: 20476
25
ASSIGNMENT::--17
Problem Statement: Write a Java Program to Find the All Fibonacci
Numbers Between n to m Where n<m And n,m <-
Natural Numbers.
Program :
import java.io.DataInputStream;
class Fibonacci
{
public static void main(String args[])
{
int n=0,m=0,a=0,b=1,sum=0,p=0;
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.println("\nEnter The Range to Find Fibonacci Numbers: ");
n=Integer.parseInt(in.readLine());
m=Integer.parseInt(in.readLine());
}
catch(Exception e)
{
System.out.println("Wrong Input");
}
sum=a+b;
System.out.println("\nThe Fibonacci Numbers Between "+n+" to "+m+" are as
Follows:\n");
if(n==0)
System.out.print(" "+a+" "+b);
while(sum<=m)
{
if(sum>=n)
{
System.out.print(" "+sum);
p++;
}
a=b;
b=sum;
sum=a+b;
}
if(p==0)
System.out.print("There are no Finonacci Numbers Between "+n+" to "+m);
System.out.println();
}
26
}
OUTPUT :-
C:\Java>javac Fibonacci.java
C:\Java>java Fibonacci
C:\Java>java Fibonacci
27
ASSIGNMENT::--18
Problem Statement: Write a Java Program to Find the All Prime
And Armstrong Numbers Between 1 to
10000.
Program :
import java.io.*;
class Prime_Amst
{
public static void main(String args[])
{
int i,c=0,sum,k,r,j,p,q;
System.out.println("\nThe Prime And Amstrong Numbers Between 1 to 10000 is as
Follows:\n");
for(i=1;i<=10000;i++)
{
p=i;
q=i;
c=0;
sum=0;
while(p!=0)
{
p=p/10;
c++;
}
while(q!=0)
{
r=q%10;
q=q/10;
sum=sum+(int) Math.pow(r,c);
}
k=0;
if(sum==i)
{
for(j=2;j<=sum/2;j++)
{
if(sum%j==0)
{
k++;
break;
}
}
if(k==0)
28
System.out.print(" "+sum);
}
}
System.out.println();
}
}
OUTPUT :-
C:\Java>javac Prime_Amst.java
C:\Java>java Prime_Amst
12357
29
ASSIGNMENT::--19
Problem Statement: Write a Java Program to Print The
Following Tringle:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
Program :
class Tringle2
{
public static void main(String args[])
{
int i,j,k,p,q;
System.out.println("\nScreen Display Done: ");
System.out.println();
q=12;
for(i=1;i<=5;i++)
{
for(k=q;k>=i;k--)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print(j+" ");
}
for(p=j-2;p>=1;p--)
{
System.out.print(p+" ");
}
System.out.println();
q=q-2;
}
}
}
30
OUTPUT :-
C:\Java>javac Tringle2.java
C:\Java>java Tringle2
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
31
ASSIGNMENT::--20
Problem Statement:Write a Java Program to Find the Nature of
The Roots And Solve The Quadratic Equation ax2+bx+c=0
Program :
import java.io.*;
class QuardeticEquation
{
public static void main(String args[])
{
int a=0,b=0,c=0;
float equ,root,root_1,root_2;
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.print("\nEnter The Value of a: ");
a=Integer.parseInt(in.readLine());
System.out.print("\nEnter The Value of b: ");
b=Integer.parseInt(in.readLine());
System.out.print("\nEnter The Value of c: ");
c=Integer.parseInt(in.readLine());
}
catch(Exception e)
{
System.out.println("Wrong Input");
}
equ=b*b-4*a*c;
if(equ==0)
{
root=-b/2*a;
System.out.println("\nThe Root is Real And Equal");
System.out.println("\nAnd The Roots Are: "+root+" And "+root);
}
if(equ>0)
{
root_1=(-b+(int) Math.sqrt(equ))/2*a;
root_2=(-b-(int) Math.sqrt(equ))/2*a;
System.out.println("\nThe Root is Real And Unequal");
System.out.println("\nAnd The Roots Are: "+root_1+" And "+root_2);
}
if(equ<0)
{
equ=(float) Math.sqrt((float) Math.abs(equ));
32
System.out.println("\nThe Root is Imaginary And Unequal");
System.out.println("\nAnd The Roots Are:("+b+"+i"+equ+")/"+2*a+" And
("+b+"-i"+equ+")/"+2*a);
}
}
}
OUTPUT :-
C:\Java>javac QuardeticEquation.java
C:\Java>java QuardeticEquation
C:\Java>java QuardeticEquation
C:\Java>java QuardeticEquation
33
ASSIGNMENT::--21
Program :
import java.io.*;
class BinaryToOctal
{
public static void main(String args[])
{
int i,j;
long Binary=0,r,Dec=0,Oct[];
Oct=new long[20];
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.print("\nEnter The Binary Number: ");
Binary=Long.parseLong(in.readLine());
}
catch(Exception e)
{
System.out.println("The Input is Error");
}
for(i=0;Binary!=0;i++)
{
r= Binary%10;
Dec=Dec+r*((long) Math.pow(2,i));
Binary= Binary/10;
}
//System.out.println(Dec);
for(i=0;Dec!=0;i++)
{
Oct[i]=Dec%8;
Dec=Dec/8;
}
System.out.print("\nThe Octal Number is: ");
for(j=i-1;j>=0;j--)
System.out.print(Oct[j]);
System.out.println();
}
}
34
OUTPUT :-
C:\Java>javac BinaryToOctal.java
C:\Java>java BinaryToOctal
35
ASSIGNMENT::--22
Problem Statement: Write a Java Program To Convert a Decimal
Number into it's Binary Equivalent.
Program :
import java.io.*;
class DecimalToBinary
{
public static void main(String args[])
{
int i;
long Binary[],Decimal=0;
Binary=new long[20];
DataInputStream in=new DataInputStream(System.in);
try
{
System.out.print("\nEnter The Decimal Number: ");
Decimal=Long.parseLong(in.readLine());
}
catch(Exception e)
{
System.out.println("The Input is Error");
}
for(i=0;Decimal!=0;i++)
{
Binary[i]=Decimal%2;
Decimal=Decimal/2;
}
System.out.print("\nThe Binary Number is: ");
for(i=i-1;i>=0;i--)
System.out.print(Binary[i]);
System.out.println();
}
}
OUTPUT :-
C:\Java>javac DecimalToBinary.java
C:\Java>java DecimalToBinary
C:\Java>java DecimalToBinary
36
The Binary Number is: 1001000
ASSIGNMENT::--23
Program :
class FiveCities
{
public static void main(String args[])
{
int i,j;
System.out.println("\nThe Five Cities Are Follows::--\n");
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
System.out.println(args[3]);
System.out.println(args[4]);
int size=args.length;
String temp=null;
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(args[j].compareTo(args[i])<0)
{
temp=args[i];
args[i]=args[j];
args[j]=temp;
}
}
}
System.out.println("\nAfter Sorting in Acceding Order The Cities Are::--\n");
for(i=0;i<size;i++)
System.out.println(args[i]);
}
}
37
OUTPUT :-
C:\Java>javac FiveCities.java
C:\Java>java FiveCities Delhi Kolkata Mumbai Bengalore Chennai
Delhi
Kolkata
Mumbai
Bengalore
Chennai
Bengalore
Chennai
Delhi
Kolkata
Mumbai
38
ASSIGNMENT::--24
Problem Statement: Write a Java Program to Implements
The Method Overloading.
Program :
class Overloading
{
void Overload(int x)
{
System.out.println("\nFirst Method:----");
System.out.println("------------------");
System.out.println("\nThe Value of X is: "+x);
}
39
System.out.println("\nThe Sum of X,Y And Z is: "+sum);
}
class Overloading
{
public static void main(String args[])
{
Ovld A=new Ovld();
A.Overload(10);
A.Overload(50,100);
A.Overload(60,10.10125,40.40505);
A.Overload(5.5005,2.210101,5.303033);
A.Overload(1200000,150,8000000,100);
}
}
OUTPUT :-
C:\Java>javac Overloading.java
C:\Java>java Overloading
First Method:----
------------------
Second Method:----
------------------
40
The Sum of X And Y is: 150
Third Method:----
------------------
Forth Method:----
------------------
Fifth Method:----
------------------
41
ASSIGNMENT::--25
Problem Statement: Write a Java Program to Implements
The Method Overriding.
Program :
class SuperClass
{
int sum;
void Show(int x,int y)
{
System.out.println("\nThe Value of X is: "+x);
System.out.println("\nThe Value of Y is: "+y);
sum=x+y;
System.out.println("\nThe Sum of X And Y is: "+sum);
}
}
class Overriding
{
public static void main(String args[])
{
SubClass Subob=new SubClass();
Subob.Show(50,20);
}
}
42
OUTPUT :-
C:\Java>javac Overriding.java
C:\Java>java Overriding
43
ASSIGNMENT::--26
Program :
interface Student
{
String name="Sourav Maity";
int roll=01;
void get_student();
}
interface Marks
{
int sub1=80,sub2=85;
void get_marks();
}
interface Sports
{
int score=100;
void get_score();
}
44
void display()
{
get_student();
get_marks();
get_score();
int sum=sub1+sub2+score;
System.out.println("\nThe Total Number is: "+sum);
}
}
class UseInterface
{
public static void main(String args[])
{
Display Obj=new Display();
Obj.display();
}
}
OUTPUT :-
C:\Java>javac UseInterface.java
C:\Java>java UseInterface
45
ASSIGNMENT::--27
Problem Statement: Write a Java Program to Implements
The Java Package.
Program :
//File Name:-Rectangle.java:-
package Package_1;
public class Rectangle
{
public int height=6,width=4;
public void get_area()
{
System.out.println("\nArea of Rectangle is: "+(height*width));
}
}
//File Name:-Circle.java:-
package Package_2;
public class Circle
{
public float r=3;
public void get_circum()
{
System.out.println("Circumference of Circle is: "+(2*3.14*r));
}
}
//File Name:-UsePackage.java:-
import Package_1.Rectangle;
import Package_2.Circle;
class UsePackage
{
public static void main(String args[])
{
Rectangle rec=new Rectangle();
Circle cir=new Circle();
float area;
int Circum;
rec.get_area();
System.out.println("Circumference of Rectangle is: "+(2*(rec.height+rec.width)));
System.out.println("\nArea of Circle is: "+(3.14*cir.r*cir.r));
cir.get_circum();
}
46
}
OUTPUT :-
C:\Java>javac UsePackage.java
C:\Java>java UsePackage
47
ASSIGNMENT::--28
Problem Statement: Write a Java Program to Implements The
Multithreads.
Program :
48
if(k==1)
try
{
sleep(1000);
}
catch(Exception e)
{
}
}
System.out.println("Exit From C");
}
}
class ThreadMethod
{
public static void main(String args[])
{
new A().start();
new B().start();
new C().start();
System.out.println("Exit From Main");
}
}
OUTPUT :-
C:\Java>javac ThreadMethod.java
C:\Java>java ThreadMethod
49
ASSIGNMENT::--29
import java.io.DataInputStream;
class VowelConsonant
{
public static void main(String args[])
{
DataInputStream in=new DataInputStream(System.in);
String s=" ";
int i,j,v=0,p=0,c=0;
try
{
System.out.print("\nEnter a String: ");
s=in.readLine();
}
catch(Exception e)
{
System.out.println("Error in Input");
}
System.out.println("\nThe Original String is: "+s);
j=s.length();
for(i=0;i<j;i++)
{
p=v;
if(s.charAt(i)=='a')
v++;
else
if(s.charAt(i)=='A')
v++;
else
if(s.charAt(i)=='e')
v++;
else
if(s.charAt(i)=='E')
v++;
else
if(s.charAt(i)=='i')
50
v++;
else
if(s.charAt(i)=='I')
v++;
else
if(s.charAt(i)=='o')
v++;
else
if(s.charAt(i)=='O')
v++;
else
if(s.charAt(i)=='u')
v++;
else
if(s.charAt(i)=='U')
v++;
if(p==v && s.charAt(i)!=' ' && s.charAt(i)!='.' && s.charAt(i)!='?')
c++;
}
System.out.println("The Number of Vowel of The string is: "+v);
System.out.println("The Number of Consonant of The string is: "+c);
}
}
OUTPUT :-
C:\Java>javac VowelConsonant.java
C:\Java>java VowelConsonant
C:\Java>java VowelConsonant
51
ASSIGNMENT::--30
Problem Statement: Write a Java Program to Short a Name of a
String (Eg-Sourav Maity.--S.Maity.).
Program :
import java.io.DataInputStream;
class ShortName
{
public static void main(String args[])
{
DataInputStream in=new DataInputStream(System.in);
String s=" ";
int i,j,k=1;
try
{
System.out.print("\nEnter a String: ");
s=in.readLine();
}
catch(Exception e)
{
System.out.println("Error in Input");
}
System.out.println("\nThe Original String is: "+s);
System.out.print("The Short Name of the String is: ");
i=s.length();
System.out.print(s.charAt(0));
for(j=0;j<i;j++)
{
if(s.charAt(j)==' ')
{
System.out.print("."+s.charAt(j+1));
k=j+2;
}
}
for(j=k;j<i;j++)
System.out.print(s.charAt(j));
System.out.println();
}
}
52
OUTPUT :-
C:\Java>javac ShortName.java
C:\Java>java ShortName
C:\Java>java ShortName
53
ASSIGNMENT::--31
Problem Statement: Write a Java Program to Convert Upper To
Lower Case And Lower To Upper Case.
Program :
import java.io.DataInputStream;
class ChangeCase
{
public static void main(String args[])
{
DataInputStream in=new DataInputStream(System.in);
String s=" ";
int i,j,k=1;
try
{
System.out.print("\nEnter a String: ");
s=in.readLine();
}
catch(Exception e)
{
System.out.println("Error in Input");
}
System.out.println("\nThe Original String is: "+s);
System.out.println("The Upper Case of the String is: "+s.toUpperCase());
System.out.println("The Lower Case of the String is: "+s.toLowerCase());
}
}
OUTPUT :-
C:\Java>javac ChangeCase.java
C:\Java>java ChangeCase
54
APPLET
***
PROGRAMING
***
ASSIGNMENT
55
Please Turn Over >>
ASSIGNMENT::--32
Problem Statement: Write Applet Java Program to Print The
Following Rectengle.
Program :
import java.awt.*;
import java.applet.*;
public class AppletRect extends Applet
{
public void paint(Graphics g)
{
g.drawRect(20,20,60,40);
g.drawLine(20,20,80,60);
g.drawLine(80,20,20,60);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletRect.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
56
OUTPUT :-
C:\Java>javac AppletRect.java
57
ASSIGNMENT::--33
Problem Statement: Write an Applet Java Program to print The
Following Circle.
Program :
import java.awt.*;
import java.applet.*;
public class AppletCircle extends Applet
{
public void paint(Graphics g)
{
g.drawOval(40,50,60,60);
g.drawOval(65,75,10,10);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletCircle.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
58
OUTPUT :-
C:\Java>javac AppletCircle.java
59
ASSIGNMENT::--34
Problem Statement: Write an Applet Java Program to print The
Following Triangle.
Program :
import java.awt.*;
import java.applet.*;
public class AppletPolygon extends Applet
{
public void paint(Graphics g)
{
Polygon Poly=new Polygon();
Poly.addPoint(50,50);
Poly.addPoint(20,80);
Poly.addPoint(80,80);
g.drawPolygon(Poly);
g.drawLine(50,50,50,80);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletPolygon.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
60
OUTPUT :-
C:\Java>javac AppletPolygon.java
61
ASSIGNMENT::--35
Program :
import java.awt.*;
import java.applet.*;
public class AppletArc extends Applet
{
public void paint(Graphics g)
{
g.drawArc(40,50,80,40,180,180);
g.drawLine(40,72,40,120);
g.drawArc(40,100,80,40,-180,-180);
g.drawLine(120,72,120,120);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletArc.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
62
OUTPUT :-
C:\Java>javac AppletArc.java
63
ASSIGNMENT::--36
Problem Statement: Write an Applet Java Program to
print The Following Face.
Program :
import java.awt.*;
import java.applet.*;
public class Face extends Applet
{
public void paint(Graphics g)
{
Polygon d=new Polygon();
g.drawOval(40,40,120,130);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
d.addPoint(100,100);
d.addPoint(90,110);
d.addPoint(110,110);
g.drawPolygon(d);
g.drawArc(70,125,60,40,-180,-180);
g.drawOval(25,92,15,30);
g.drawOval(160,92,15,30);
g.drawLine(98,150,102,150);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
64
CODE="Face.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
OUTPUT :-
C:\Java>javac Face.java
65
ASSIGNMENT::--37
Problem Statement: Write a Java Applet Program to Draw a
Triangle,A Rectangle and a Circle with
Same Centre.
Program :
import java.awt.*;
import java.applet. *;
public class AppletRecTraCir extends Applet
{
public void paint(Graphics g)
{
Polygon P=new Polygon();
g.drawOval(50,50,100,100);
g.drawRect(70,70,60,60);
P.addPoint(100,75);
P.addPoint(75,125);
P.addPoint(125,125);
g.drawPolygon(P);
g.fillOval(98,102,5,5);
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletRecTraCir.class"
width=400
66
Height=400>
</APPLET>
</BODY>
</HTML>
OUTPUT :-
C:\Java>javac AppletRecTraCir.java
67
ASSIGNMENT::--38
Problem Statement: Write a Java Applet Program to Find The
Biggest And Smallest Number.
Program :
import java.awt.*;
import java.applet.*;
public class AppletBig extends Applet
{
TextField text1,text2,text3;
public void init()
{
text1=new TextField(8);
text2=new TextField(8);
text3=new TextField(8);
add(text1);
add(text2);
text1.setText("0");
text2.setText("0");
text3.setText("0");
}
public void paint(Graphics g)
{
int w=0,x=0,y=0,z=0;
String s1,s2,s3,s;
g.drawString("Input a Number in Each Box",10,50);
try
{
s1=text1.getText();
w=Integer.parseInt(s1);
s2=text2.getText();
x=Integer.parseInt(s2);
s3=text2.getText();
y=Integer.parseInt(s3)
}
catch(Exception e)
{
}
z=s1;
if(s2>z)
68
z=s2;
if(s3>z)
z=s3;
s=String.valueOf(z);
g.drawString("The Sum Is: ",10,75);
g.drawString(s,100,75);
}
public boolean action(Event event,Object object)
{
repaint();
return true;
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletBig.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
OUTPUT :-
C:\Java>javac AppletBig.java
69
ASSIGNMENT::--39
Problem Statement: Write a Java Applet Program to Find The
Factorial of a Number.
Program :
import java.awt.*;
import java.applet.*;
public class AppletFact extends Applet
{
TextField text1;
public void init()
{
text1=new TextField(8);
add(text1);
text1.setText("0");
}
public void paint(Graphics g)
{
int x=0,i,fact=1;
String s1,s;
g.drawString("Input a Number in The Box",10,50);
try
{
s1=text1.getText();
x=Integer.parseInt(s1);
}
70
catch(Exception e)
{
}
if(x>=0)
{
for(i=x;i>0;i--)
{
fact=fact*i;
}
s=String.valueOf(fact);
g.drawString("The Factorial of The Number Is: ",10,80);
g.drawString(s,200,80);
}
else
g.drawString("The Factorial of The Number Is: ",10,80);
}
public boolean action(Event event,Object object)
{
repaint();
return true;
}
}
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="AppletFact.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
OUTPUT :-
C:\Java>javac AppletFact.java
71
ASSIGNMENT::--40
Problem Statement: Develop an Applet to Draw Four Triangles
in a Row. Any Triangle should not be
overlapped to Any Other Triangle and
Filled with Different Color.
Program :
import java.awt.*;
import java.applet.*;
public class FourTriangles extends Applet
{
public void paint(Graphics g)
{
Polygon poly=new Polygon();
poly.addPoint(40,40);
poly.addPoint(20,60);
poly.addPoint(60,60);
g.setColor(Color.red);
g.fillPolygon(poly);
72
p.addPoint(60,100);
g.setColor(Color.blue);
g.fillPolygon(p);
HTML PROGRAM
<HTML>
<HEAD>
<TITLE>Applet Program</TITLE>
</HEAD>
<BODY>
<APPLET
CODE="FourTriangles.class"
width=400
Height=400>
</APPLET>
</BODY>
</HTML>
OUTPUT :-
C:\Java>javac FourTriangles.java
73
HTML
***
PROGRAMING
74
***
ASSIGNMENT
REGISTAR FORM.HTML:-
<HTML>
<HEAD>
<TITLE>REGISTAR FORM</TITLE>
</HEAD>
<BODY BGCOLOR=PINK>
<CENTER><TABLE BORDER=1>
<H1>REGISTAR FORM</H1>
<TR><TD>NAME</TD><TD><INPUT TYPE=TEXT></TD></TR>
<TR><TD>AGE</TD><TD><INPUT TYPE=TEXT></TD></TR>
<TR><TD>ADDRESS</TD><TD><TEXTAREA ROWS=10,COLS=40></TEXTAREA></TD></TR>
<TR><TD>COUNTRY</TD><TD><SELECT><OPTION>INDIA</OPTION>
<OPTION>AUSTRALIA</OPTION><OPTION>SRILANKA</OPTION>
<OPTION>BANGLADESH</OPTION><OPTION>PAKISTHAN</OPTION></TD></TR>
75
<TR><TD>GENDAR</TD><TD><INPUT TYPE=RADIO NAME=A>M
<INPUT TYPE=RADIO NAME=A>F</TD></TR>
<TR><TD>LANGUAGE</TD><TD><INPUT TYPE=CHECKBOX>E
<INPUT TYPE=CHECKBOX>B
<INPUT TYPE=CHECKBOX>H</TD></TR>
<TR><TD><INPUT TYPE=BUTTON VALUE=SUBMIT></TD>
<TD><INPUT TYPE=RESET></TD></TR>
</CENTER>
</TABLE>
</BODY>
</HTML>
OUTPUT :-
76
ASSIGNMENT::--42
Problem Statement: Write a HTML Programe To Display All BCA
5’th Semester Students(10 Students Per
Page) And Give There Details(Name,Phone
No., e_mail,Address,DOB And Age).
77
BCA5’TH SEM.HTML:-
<HTML>
<HEAD>
<TITLE>BCA RECORDS</TITLE>
</HEAD>
<BODY BGCOLOR="PINK">
<CENTER>
<H1>BELDA COLLEGE</H1><BR><BR>
<H2>BCA 5'th SEMESTER STUDENTS DETAILS</H2>
<BR><BR><BR><BR>
<A HREF="RECORD-1.HTML">Click Here To Show The Students Details </A>
</CENTER></BODY>
</HTML>
RECORD-2.HTML:-
<HTML>
<HEAD>
78
<TITLE>BCA RECORDS</TITLE>
</HEAD>
<BODY BGCOLOR="PINK">
<CENTER><H1>BCA 5'th SEMESTER</H1>
<BR>
<TABLE BORDER=1 BGCOLOR="SKY BLUE">
<TR><TD><H2>ROLL NO.</H2></TD><TD><H2>NAME</H2></TD></TR>
<TR><TD>1301</TD><TD><A HREF="SOURAV.HTML">
<H3>Sourav Maity</H3></A></TD></TR>
<TR><TD>1302</TD><TD><A HREF="ARUN.HTML">
<H3>Arun Mahapatra</H3></A></TD></TR>
<TR><TD>1305</TD><TD><A HREF="PRASUN.HTML">
<H3>Prasun Pradhan</H3></A></TD></TR>
<TR><TD>1306</TD><TD><A HREF="SUBHANKAR.HTML">
<H3>Subhankar Manna</H3></A></TD></TR>
<TR><TD>1307</TD><TD><A HREF="SUKALYN.HTML">
<H3>Sukalyn Basuri</H3></A></TD></TR>
<TR><TD>1308</TD><TD><A HREF="SOUMAN.HTML">
<H3>Souman Day</H3></A></TD></TR>
<TR><TD>1309</TD><TD><A HREF="AVIJIT.HTML">
<H3>Avijit Das</H3></A></TD></TR>
<TR><TD>1310</TD><TD><A HREF="DINASH.HTML">
<H3>Dinash Das </H3></A></TD></TR>
<TR><TD>1315</TD><TD><A HREF="PIJUSH.HTML">
<H3>Pijush Panday</H3></A></TD></TR>
<TR><TD>1316</TD><TD><A HREF="CHINMOY.HTML">
<H3>Chinmoy Mitra</H3></A></TD></TR>
</TABLE>
<A HREF="RECORD-2.HTML"><H4 ALIGN=RIGHT>Next Page>></H4></A>
<A HREF="BCA 5'TH SEM.HTML"><H4 ALIGN=LEFT>Back</H4></A>
<A HREF="BCA 5'TH SEM.HTML">Goto Home Page </A>
</CENTER>
</BODY>
</HTML>
79
80
SOURAV.HTML:-
<HTML>
<HEAD>
<TITLE>STUDENT DETAILS</TITLE></HEAD>
<BODY BGCOLOR="PINK">
<CENTER><BR><BR>
<H2>DETAILS OF Sourav Maity</H2><BR><BR>
<H3>NAME: Sourav Maity</H3>
<H3>ROLL NO. : 1301</H3>
<H3>ADDRESS: Belda,Paschim Medinipur,PIN-721424</H3>
<H3>E_mail ID: b2kgpsm@gmail.com</H3>
<H3>PHONE NO. : 9635368004</H3>
<H3>DOB: 24/07/1991</H3>
<H3>AGE: 20</H3>
<BR><BR><BR><BR>
<A HREF="ARUN.HTML"><H4 ALIGN=RIGHT>Next Page>></H4></A>
<A HREF="RECORD-2.HTML"><H4 ALIGN=LEFT>Back</H4></A>
<BR><BR>
<A HREF="BCA 5'TH SEM.HTML">Goto Home Page </A>
</CENTER></BODY>
</HTML>
ASSIGNMENT::--43
81
Problem Statement: Write a HTML Program To Show All ICC
Cricket Teams And Gives The Details Of All
Players With There Name,Age,Match,Run
etc in ODI And Test Matches.
ICC TEAMS.HTML:-
<HTML>
<HEAD><TITLE>ICC CRICKET TEAM</TITLE></HEAD>
<BODY BGCOLOR=PINK>
<CENTER><H1>ICC CRICKET TEAM</H1>
<BR><HR><BR><BR><TABLE BORDER=1>
<TR><TD><A HREF="INDIA TEAM.HTML">INDIA</A></TD></TR>
<TR><TD><A HREF="AUSTRALIA TEAM.HTML">AUSTRALIA</A></TD></TR>
<TR><TD><A HREF="SRILANKA TEAM.HTML">SRILANKA</TD></TR>
<TR><TD><A HREF="SOUTH AFRIKA TEAM.HTML">SOUTH AFRIKA</TD></TR>
<TR><TD><A HREF="PAKISTHAN TEAM.HTML">PAKISTHAN</A></TD></TR>
<TR><TD><A HREF="NEW ZELAND TEAM.HTML">NEW ZELAND</A></TD></TR>
<TR><TD><A HREF="WEST INDIES TEAM.HTML">WEST INDIES</A></TD></TR>
<TR><TD><A HREF="BANGLADESH TEAM.HTML">BANGLADESH</A></TD></TR>
</CENTER></TABLE></BODY></HTML>
INDIA TEAM.HTML:-
<HTML>
82
<HEAD>
<TITLE>INDIA CRICKET TEAM</TITLE>
</HEAD>
<BODY BGCOLOR=PINK>
<CENTER><H1>INDIA CRICKET TEAM</H1>
<BR><BR><H3>
<OL><LI><A HREF="SACHIN.HTML">SACHIN TENDULKAR</A></LI>
<LI><A HREF="SOURAV.HTML">SOURAV GANGULY</A></LI>
<LI><A HREF="SEHWAG.HTML">VIRENDRA SEHWAG</A></LI>
<LI><A HREF="DRAVID.HTML">RAHUL DRAVID</A></LI>
<LI><A HREF="YUVRAJ.HTML">YUVRAJ SINGH</A></LI>
<LI><A HREF="LAXMAN.HTML">V.V.S LAXMAN</A></LI>
<LI><A HREF="RAINA.HTML">SURESH RAINA</A></LI>
<LI><A HREF="DHONI.HTML">MOHENDRASINGH DHONI</A></LI>
<LI><A HREF="DINESH.HTML">DINESHI KARTIK</A></LI>
<LI><A HREF="KUMBLE.HTML">ANIL KUMBLE</A></LI>
<LI><A HREF="HARBHAJAN.HTML">HARBHAJAN SINGH</A></LI>
<LI><A HREF="ZAHER.HTML">ZAHER KHAN</A></LI>
<LI><A HREF="SRISANTH.HTML">S.SRISANTH</A></LI>
<LI><A HREF="ASHIS.HTML">ASHIS NEHERA</A></LI>
<LI><A HREF="ISHANT.HTML">ISHANT SHARMA</A></LI></OL>
</H3><BR><BR><BR><BR>
<A HREF="ICC TEAMS.HTML"><H4>Goto Home Page</H4></A>
<BR>
<A HREF="ICC TEAMS.HTML"><H4>Back</H4></A>
</CENTER>
<A HREF="AUSTRALIA TEAM.HTML"><H4 ALIGN=RIGHT>Next Page>></H4></A>
</TABLE>
</BODY>
</HTML>
83
SACHIN.HTML:-
<HTML>
<HEAD>
<TITLE>SACHIN</TITLE>
</HEAD>
<BODY BGCOLOR=PINK>
<CENTER><H1>Sachin Ramesh Tendelkar</H1>
<H2>Age: 36</H2>
</CENTER>
<H2>ONE DAY MATCH PERFORMANCE::--</H2>
<TABLE BORDER=1><H3>
<TR><TD>MATCH</TD><TD>442</TD></TR>
<TR><TD>RUNS</TD><TD>17260</TD></TR>
<TR><TD>50'S</TD><TD>90</TD></TR>
<TR><TD>100'S</TD><TD>45</TD></TR>
<TR><TD>HIGHEST SCORE</TD><TD>186*</TD></TR>
<TR><TD>WICKETS</TD><TD>160</TD></TR>
</TABLE></H3>
<CENTER>
<H2>TEST MATCH PERFORMANCE::--</H2>
<TABLE BORDER=1><H3>
<TR><TD>MATCH</TD><TD>164</TD></TR>
<TR><TD>RUNS</TD><TD>13678</TD></TR>
<TR><TD>50'S</TD><TD>54</TD></TR>
<TR><TD>100'S</TD><TD>45</TD></TR>
84
<TR><TD>200'S</TD><TD>4</TD></TR>
<TR><TD>HIGHEST SCORE</TD><TD>248*</TD></TR>
<TR><TD>WICKETS</TD><TD>80</TD></TR>
</TABLE></H3>
<A HREF="SOURAV.HTML"><H4 ALIGN=RIGHT>Next Page>></H4></A>
<A HREF="ICC TEAMS.HTML"><H4>Goto Home Page</H4></A>
<A HREF="INDIA TEAM.HTML"><H4>Back</H4></A>
</CENTER>
</BODY>
</HTML>
85
FRAMESET.HTML:-
<HTML>
<HEAD>
<TITLE>FRAMSET EXAMPLE</TITLE>
<FRAMESET COLS="30%,30%,30%">
<FRAME SRC="ICC TEAMS.HTML">
<FRAME SRC="INDIA TEAM.HTML">
<FRAME SRC="SOURAV.HTML">
</FRAMESET></FRAMESET></FRAMESET>
</HEAD>
</HTML>
86