MADURAI KAMARAJAR UNIVERSITY
DEVANGA ARTS COLLEGE
Reaccredited and Graded ‘A’ by NAAC
ARUPPUKOTTAI - 626101
RECORD NOTE BOOK
DEPARTMENT OF INFORMATION TECHNOLOGY (UG)
Name :
Reg. No. :
Subject : JAVA PROGRAMMING
Subject Code : (SNTJC41)
MADURAI KAMARAJAR UNIVERSITY
DEVANGA ARTS COLLEGE
Reaccredited and Graded ‘A’ by NAAC
ARUPPUKOTTAI - 626101.
NAME :
II [Link]. (IT)
CLASS :
REGISTER No. :
This is certified that the bonafide record of
PRACTICAL WORK
Done by Reg. No.
in the Computer Laboratory.
Head of the Department Staff-In-Charge
Submitted for Autonomous Practical Examination APRIL2022
held
on at Devanga Arts College, Aruppukottai.
Internal Examiner External Examiner
CONTENTS
PAGE
[Link]. DATE TITLE SIGN
NO.
1 02/01/23 Sum of Digits
2 04/01/23 Armstrong Number
3 11/01/23 Prime or Number
4 31/01/23 Reverse With Palindrome
5 06/02/23 Area of Calculation
6 13/02/23 Complex Addition
7 15/02/23 Windows Application
8 22/02/23 File Copy
9 09/03/23 String Manipulation
10 15/03/23 Matrix Multiplication
11 16/03/23 Arithmetic operations
12 24/03/23 Sorting Number
13 27/03/23 Digital Clock
14 31/03/23 Human Face
15 01/04/23 Scrolling Text Using Applet and Thread
16 11/04/23 Change Background Color
17 12/04/23 Label Components
Ex. No:
Date:02
SUM OF
DIGITS
AIM:
To write a java program for Sum of Digits.
PROGRAM:
import [Link].*;
import [Link].*;
class sum
{
public static void main(String args[])throws IOException
{
DataInputStream d= new DataInputStream([Link]);
int a,s=0,r;
[Link]("\t SUM OF DIGIT\n");
[Link]("\t-------------\n");
[Link]("Enter the Value:");
a=[Link]([Link]());
while(a>0)
{
r=a%10;
s=s+r;
a=a/10;
}
[Link]("The result is=" +s);
}
}
OUTPUT:
D:\jdk1.5.0_05\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java sum
SUM OF DIGIT
-----------------------
Enter the Value:
45
The result is=9
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
ARMSTRONG
Date:04/01
/23 NUMBER
AIM:
To write a java program for to check given number is Armstrong or
Not.
PROGRAM:
import [Link].*;
class arms
{
public static void main(String args[])throws IOException
{
int n,i,p,n1,r,b;
{
DataInputStream d= new DataInputStream([Link]);
[Link]("\t ARMSTRONG NUMBER\n");
[Link]("\t ****************\n");
[Link]("Enter the Value:");
n=[Link]([Link]());
n1=n;
p=0;
while(n!=0)
{
r=n%10;
p=p+(r*r*r);
n=n/10;
}
if(p==n1)
[Link](n1+"is a Armstrong Number");
else
[Link](n1+" is not Armstrong Number");
}
}
}
OUTPUT:
D:\jdk1.5.0_05\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java arms
ARMSTRONG NUMBER
**********************
Enter the Value:
153
153is a Armstrong Number
D:\jdk1.5.0_05\bin>java arms
ARMSTRONG NUMBER
***********************
Enter the Value:
895
895 is not Armstrong Number
D:\jdk1.5.0_05\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
PRIME NUMBER
Date:11/0
1/23
AIM:
To write a java program for to check given number is Prime or Not.
PROGRAM:
import [Link].*;
class prime
{
public static void main(String args[])throws IOException
{
int n,i,p,a;
DataInputStream d= new DataInputStream([Link]);
[Link]("\tPRIME NUMBER\n");
[Link]("\t************\n");
[Link]("\tEnter the Value:\n");
n=[Link]([Link]());
p=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
p=p+1;
}
if(p==1)
[Link](n+" is Neither Prime nor Composite");
else if(p==2)
[Link](n+"is a Prime Number");
else
[Link](n+"is not a Prime Number");
}
}
OUTPUT:
D:\jdk1.5.0_05\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java prime
PRIME NUMBER
****************
Enter the Value:
1
1 is Neither Prime nor Composite
D:\jdk1.5.0_05\bin>java prime
PRIME NUMBER
****************
Enter the Value:
45
45is not a Prime Number
D:\jdk1.5.0_05\bin>java prime
PRIME NUMBER
****************
Enter the Value:
13
13is a Prime Number
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No: REVERSE WITH
Date:31/0
1/23 PALINDROME
AIM:
To write a java program for to check whether the given number is
Palindrome or Not.
PROGRAM:
import [Link].*;
class rev
{
public static void main(String args[])throws IOException
{
String s,s1;
DataInputStream str= new DataInputStream([Link]);
[Link]("\tREVERSE WITH PALINDROME\n");
[Link]("\t**********************\n");
[Link]("Enter the String:");
s=[Link]();
StringBuffer sb=new StringBuffer(s);
[Link]();
s1=[Link]();
[Link]("The Reverse String is:"+sb);
if([Link](s))
{
[Link]("The string is Palidrome");
}
else
{
[Link]("The string is Not Palidrome");
}
}
}
OUTPUT:
D:\jdk1.5.0_05\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java rev
REVERSE WITH PALINDROME
*******************************
Enter the String:
mathi
The Reverse String is:ihtam
The string is Not Palidrome
D:\jdk1.5.0_05\bin>java rev
REVERSE WITH PALINDROME
*******************************
Enter the String:
madam
The Reverse String is:madam
The string is Palidrome
D:\jdk1.5.0_05\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
Date:06/0
AREA OF
CALCULATION
AIM:
To write a java program for Area of Calculation.
PROGRAM:
import [Link].*;
import [Link];
class area1
{
public static void main(String args[])throws IOException
{
int x,ch,b1,h;
String a;
double r,l,b;
[Link]("\t\tAREA CALCULATION");
[Link]("\t\t-----------------");
DataInputStream d=new DataInputStream([Link]);
[Link]("[Link] \[Link] \[Link]");
shape s1=new shape();
do
{
[Link]("Enter your choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]("AREA OF CIRCLE");
[Link]("------------------");
[Link]("ENTER THE RADIOUS VALUE");
r=[Link]([Link]());
[Link]("THE ANSWER IS");
[Link](r);
break;
case 2:
[Link]("AREA OF TRAINGLE");
[Link]("------------------");
[Link]("ENTER THE BASE AND HEIGHT VALUE");
b1=[Link]([Link]());
h=[Link]([Link]());
[Link]("THE ANSWER IS");
[Link](b1,h);
break;
case 3:
[Link]("AREA OF RECTANGLE");
[Link]("------------------");
[Link]("ENTER THE LENGTH AND BREATH VALUE");
l=[Link]([Link]());
b=[Link]([Link]());
[Link]("THE ANSWER IS");
[Link](l,b);
break;
default:
[Link]("DOES NOT MATCH");
}
[Link]("DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO");
x=[Link]([Link]());
}while(x==1);
}
}
class shape
{
double c,re,t;
void add(double x)
{
c=3.14*x*x;
[Link]("AREA OF CIRCLE IS="+c);
}
void add(int y,int z)
{
t=0.5*y*z;
[Link]("AREA OF TRAINGLE IS="+t);
}
void add(double l1,double l2)
{
re=l1*l2;
[Link]("AREA OF RECTANGLE IS="+re);
}
}
OUTPUT:
D:\jdk1.5.0_05\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java area1
AREA CALCULATION
--------------------------------
[Link]
[Link]
[Link]
Enter your choice:
1
AREA OF CIRCLE
--------------------------
ENTER THE RADIOUS VALUE
2
THE ANSWER IS
AREA OF CIRCLE IS=12.56
DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO
1
Enter your choice:
2
AREA OF TRAINGLE
--------------------------------
ENTER THE BASE AND HEIGHT VALUE
5
6
THE ANSWER IS
AREA OF TRAINGLE IS=15.0
DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO
1
Enter your choice:
3
AREA OF RECTANGLE
----------------------------------
ENTER THE LENGTH AND BREATH VALUE
2
3
THE ANSWER IS
AREA OF RECTANGLE IS=6.0
DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO
1
Enter your choice:
4
DOES NOT MATCH
DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO
0
D:\jdk1.5.0_05\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
COMPLEX
Date:13/0
AIM:
To write a java program for Complex Addition.
PROGRAM:
import [Link].*;
class comp
{
public static void main(String args[])throws IOException
{
int r,r1,i,i1,x,y;
[Link]("\t\tCOMPLEX ADDITION");
[Link]("\t\t-----------------");
DataInputStream d=new DataInputStream([Link]);
[Link]("Enter the First Real and Imaginary Number:");
r=[Link]([Link]());
i=[Link]([Link]());
[Link]("Enter the Second Real and Imaginary Number:");
r1=[Link]([Link]());
i1=[Link]([Link]());
x=r+r1;
y=i+i1;
[Link]("THE ANSWER IS:");
if(y==0)
[Link](x);
else
{
if(x==0)
[Link](+y+"i");
else
{
if(y>0)
[Link]("\t"+x+"+i"+y);
else
[Link]("\t"+x+"-i"+(-y));
}
}
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java comp
COMPLEX ADDITION
---------------------------------
Enter the First Real and Imaginary Number:
23
14
Enter the Second Real and Imaginary Number:
11
45
THE ANSWER IS:
34+i59
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No: EXCUTING VARIOUS
7
WINDOWS
Date:15/02
/23 APPLICATIONS
AIM:
To write a java program for to Execute Various Windows
Application.
PROGRAM:
import [Link].*;
import [Link].* ;
class win
{
public static void main(String args[])throws IOException
{
int ch;
DataInputStream ob=new DataInputStream([Link]);
do
{
[Link]("*********************************************");
[Link]("Executing Various Windows Application");
[Link]("*********************************************");
[Link]("\n 1-Notepad\n 2-Paint\n 3-Calculator\n 4-Explorer\n 5-
Exit\n");
Runtime r=[Link]();
Process p=null;
[Link]("Enter your choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
try
{
p=[Link]("[Link]");
[Link]("Notepad is opened");
}
catch(Exception e)
{
[Link]("\n Error in Notepad");
}
break;
case 2:
try
{
p=[Link]("[Link]");
[Link]("Paint is Opened");
}
catch(Exception e)
{
[Link]("Error in paint");
}
break;
case 3:
try
{
p=[Link]("[Link]");
[Link]("Calculator is opened");
}
catch(Exception e)
{
[Link]("\n Error in Calculator");
}
break;
case 4:
try
{
p=[Link]("[Link]");
[Link]("Explorer is opened");
}
catch(Exception e)
{
[Link]("\n Error in Exception");
}
break;
case 5:
[Link]("Exit the program");
[Link](0);
default:
[Link]("Invalid Choice");
break;
}
}
while(ch!=5);
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java win
*********************************************
Executing Various Windows Application
*********************************************
1-Notepad
2-Paint
3-Calculator
4-Explorer
5-Exit
Enter your choice:1
Notepad is opened
*********************************************
Executing Various Windows Application
*********************************************
1-Notepad
2-Paint
3-Calculator
4-Explorer
5-Exit
Enter your choice:2
Paint is Opened
*********************************************
Executing Various Windows Application
*********************************************
1-Notepad
2-Paint
3-Calculator
4-Explorer
5-Exit
Enter your choice:3
Calculator is opened
*********************************************
Executing Various Windows Application
*********************************************
1-Notepad
2-Paint
3-Calculator
4-Explorer
5-Exit
Enter your choice:4
Explorer is opened
*********************************************
Executing Various Windows Application
*********************************************
1-Notepad
2-Paint
3-Calculator
4-Explorer
5-Exit
Enter your choice:5
Exit the program
D:\jdk1.5.0\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
Date:22/0
FILE COPY
2/23
AIM:
To write a java program for to Copy the Content from one File to
another File.
PROGRAM:
import [Link].*;
class filecopy
{
public static void main(String args[])throws IOException
{
int i;
String src,des;
DataInputStream ob=new DataInputStream([Link]);
[Link]("Enter the Source File Name:");
src=[Link]();
[Link]("Enter the Destination File Name:");
des=[Link]();
try
{
FileInputStream fin=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(des);
do
{
i=[Link]();
if(i!=-1)
{
[Link]((char)i);
[Link](i);
}
}
while(i!=-1);
[Link]("\nSource File: "+src+" is Successfully Copied to
Destination File:"+des);
}
catch(IOException e)
{
[Link]("\nFile Error"+e);
}
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java filecopy
Enter the Source File Name:[Link]
Enter the Destination File Name:[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Source File: [Link] is Successfully Copied to Destination File:[Link]
D:\jdk1.5.0\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
9 STRING
Date:09/03
/23 MANIPULATION
AIM:
To write a java program for String Manipulation.
PROGRAM:
import [Link].*;
class strfn
{
public static void main(String args[])throws IOException
{
String s1,s2;
int st,ed,p,ch;
DataInputStream ob=new DataInputStream([Link]);
do
{
[Link]("\n******************");
[Link]("String Function");
[Link]("******************");
[Link]("\n 1-Length\n 2-CharAt\n 3-SubString\n 4-Equals\n 5-
EqualsIgnoreCase\n 6-Replace\n 7-Concatenation\n 8-Trim\n 9-UpperCase\n
10-LowerCase\n 11-Reverse\n 12-Copy\n 13-Exit\n");
[Link]("Enter your choice:");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]("Enter any String:");
s1=[Link]();
[Link]("\n \tStringLength is:"+[Link]());
break;
case 2:
[Link]("Enter any string:");
s1=[Link]();
[Link]("Enter the Position:");
p=[Link]([Link]());
[Link]("\n \tCharacter is:"+[Link](p));
break;
case 3:
[Link]("Enter any String:");
s1=[Link]();
[Link]("Enter the Starting position:");
st=[Link]([Link]());
[Link]("Enter the ending Position:");
ed=[Link]([Link]());
[Link]("\n \tSubString is :"+[Link](st,ed));
break;
case 4:
[Link]("Enter 1st String:");
s1=[Link]();
[Link]("Enter 2nd String:");
s2=[Link]();
if([Link](s2))
[Link]("\n \tBoth String are Equal");
else
[Link]("\n \tBoth String are not Equal");
case 5:
[Link]("Enter 1st String:");
s1=[Link]();
[Link]("Enter 2nd String:");
s2=[Link]();
if([Link](s2))
[Link]("\n \tBoth String are Equal");
else
[Link]("\n \tBoth String are not Equal");
break;
case 6:
[Link]("Enter any String:");
s1=[Link]();
s2=[Link]('a','e');
[Link]("\n \tAfter Replacement is:"+s2);
break;
case 7:
[Link]("Enter 1st String:");
s1=[Link]();
[Link]("Enter 2nd String:");
s2=[Link]();
[Link]("\n \tConcatenation of String is:"+[Link](s2));
break;
case 8:
[Link]("Enter any String:");
s1=[Link]();
[Link]("\n \tTrimmed String is:"+[Link]());
break;
case 9:
[Link]("Enter any String:");
s1=[Link]();
[Link]("\n \tUpperCase String is:"+[Link]());
break;
case 10:
[Link]("Enter any String:");
s1=[Link]();
[Link]("\n \tLowerCase String is:"+[Link]());
break;
case 11:
[Link]("Enter any String:");
s1=[Link]();
StringBuffer sb=new StringBuffer(s1);
[Link]("\n \tReverse String is:"+[Link]());
break;
case 12:
[Link]("Enter any String:");
s1=[Link]();
s2=s1;
[Link]("\n \tCopied String is:"+s2);
break;
case 13:
[Link]("Exit the program");
[Link](0);
default:
[Link]("Invalid Choice");
break;
}
}
while(ch!=13);
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java strfn
******************
String Function
******************
1-Length
2-CharAt
3-SubString
4-Equals
5-EqualsIgnoreCase
6-Replace
7-Concatenation
8-Trim
9-UpperCase
10-LowerCase
11-Reverse
12-Copy
13-Exit
Enter your choice:
1
Enter any String:
mathi
StringLength is:5
Enter your choice:
2
Enter any string:
raja
Enter the Position:2
Character is:j
Enter your choice:
3
Enter any String:rajasankar
Enter the Starting position:4
Enter the ending Position:6
SubString is :sa
Enter your choice:
4
Enter 1st String:mathi
Enter 2nd String:raj
Both String are not Equal
Enter 1st String:mathi
Enter 2nd String:mathi
Both String are Equal
Enter your choice:
5
Enter 1st String:mathi
Enter 2nd String:mathi
Both String are Equal
Enter your choice:
5
Enter 1st String:Mathi
Enter 2nd String:mathi
Both String are Equal
Enter your choice:
5
Enter 1st String:MATHI
Enter 2nd String:mathi
Both String are Equal
Enter your choice:
4
Enter 1st String:Mathi
Enter 2nd String:mathi
Both String are not Equal
Enter 1st String:sasi
Enter 2nd String:sasi
Both String are Equal
Enter your choice:
6
Enter any String:mathi
After Replacement is:methi
Enter your choice:
7
Enter 1st String:raj
Enter 2nd String:ravi
Concatenation of String is:rajravi
Enter your choice:
8
Enter any String: mathi
Trimmed String is:mathi
Enter your choice:
8
Enter any String:raja
Trimmed String is:raja
Enter your choice:
9
Enter any String:mathi
UpperCase String is:MATHI
Enter your choice:
10
Enter any String:MATHI
LowerCase String is:mathi
Enter your choice:
11
Enter any String:ram
Reverse String is:mar
Enter your choice:
12
Enter any String:valar
Copied String is:valar
Enter your choice:
14
Invalid Choice
Enter your choice:
13
Exit the program
D:\jdk1.5.0\bin>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
10
MATRIX
Date: MULTIPLICATION
15/03/23
AIM:
To write a java program for Matrix Multiplication.
PROGRAM:
import [Link].*;
class matmul
{
public static void main(String args[])throws IOException
{
int m,n,p,q,sum=0,i,j,k;
int a[][],b[][],c[][];
DataInputStream ob=new DataInputStream([Link]);
[Link]("\n\t\t*********************");
[Link]("\t\tMATRIX MULTIPLICATION");
[Link]("\t\t*********************");
[Link]("Enter the number of rows and columns of first matrix:");
m=[Link]([Link]());
n=[Link]([Link]());
[Link]("Enter the number of rows and columns of second
matrix:");
p=[Link]([Link]());
q=[Link]([Link]());
if (n!=p)
{
[Link]("\n MATRIX MULTIPLICATION CANNOT PERFORMED");
[Link](0);
}
else
{
a=new int[m][n];
b=new int[p][q];
c=new int[m][q];
[Link]("Enter the element of first matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=[Link]([Link]());
[Link]("Enter the elements of second matrix:");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
b[i][j]=[Link]([Link]());
[Link]("FIRST MATRIX IS:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
[Link](a[i][j]+"\t");
}
[Link]();
}
[Link]("SECOND MATRIX IS:");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
[Link](b[i][j]+"\t");
}
[Link]();
}
[Link]("MATRIX MULTIPLICATION IS:");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
[Link](c[i][j]+"\t");
sum=0;
}
[Link]("\n");
}
}
}
}
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java matmul
***************************
MATRIX MULTIPLICATION
***************************
Enter the number of rows and columns of first matrix:
2
2
Enter the number of rows and columns of second matrix:
2
2
Enter the element of first matrix:
2
3
1
2
Enter the elements of second matrix:
3
3
3
4
FIRST MATRIX IS:
2 3
1 2
SECOND MATRIX IS:
3 3
3 4
MATRIX MULTIPLICATION IS:
15 18
9 11
D:\jdk1.5.0\bin>java matmul
***************************
MATRIX MULTIPLICATION
***************************
Enter the number of rows and columns of first matrix:
3
2
Enter the number of rows and columns of second matrix:
3
3
MATRIX MULTIPLICATION CANNOT PERFORMED
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
11
SORTING NUMBER
Date:16/0
3/23
AIM:
To write a java program for Sorting Number.
PROGRAM:
import [Link].*;
class sorting
{
public static void main(String args[])throws IOException
{
int k[]=new int[10],n,i,j,t;
[Link]("\tSORTING NUMBER");
[Link]("\t-----------------------");
DataInputStream d=new DataInputStream([Link]);
[Link]("Enter Array Size:");
n=[Link]([Link]());
[Link]("Enter the Numbers:");
for(i=0;i<n;i++)
{
k[i]=[Link]([Link]());
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(k[i]>k[j])
{
t=k[i];
k[i]=k[j];
k[j]=t;
}
[Link]("ASCENDING ORDER:");
for(i=0;i<n;i++)
[Link](k[i]+"\n");
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0\bin>java sorting
SORTING NUMBER
-----------------------------
Enter Array Size:
5
Enter the Numbers:
89
12
53
03
47
ASCENDING ORDER:
3
12
47
53
89
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
12
ARITHMETIC
Date:24/03
/23
OPERATION USING
AIM:
To write a java program for Arithmetic Operation Using Packages
PROGRAM:
import [Link].*;
import arith.*;
class arithm
{
public static void main(String args[])throws IOException
{
String s;
int a,b,x,ch;
double c,c1;
[Link]("ARITHMETIC OPERATION\n");
[Link]("-----------------------------------\n");
[Link]("[Link]\[Link]\[Link]\
[Link]");
DataInputStream d=new DataInputStream([Link]);
operation o=new operation();
do
{
[Link]("ENTER YOUR CHOICE:\n");
ch=[Link]([Link]());
switch(ch)
{
case 1:
[Link]("ADDITION\n");
[Link]("--------------\n");
[Link]("ENTER THE FIRST VALUE:\n");
a=[Link]([Link]());
[Link]("ENTER THE SECOND VALUE:\n");
b=[Link]([Link]());
[Link](a,b);
break;
case 2:
[Link]("SUBTRACTION\n");
[Link]("--------------\n");
[Link]("ENTER THE FIRST VALUE:\n");
a=[Link]([Link]());
[Link]("ENTER THE SECOND VALUE:\n");
b=[Link]([Link]());
[Link](a,b);
break;
case 3:
[Link]("MULTIPLICATION\n");
[Link]("--------------\n");
[Link]("ENTER THE FIRST VALUE:\n");
a=[Link]([Link]());
[Link]("ENTER THE SECOND VALUE:\n");
b=[Link]([Link]());
[Link](a,b);
break;
case 4:
[Link]("DIVISION\n");
[Link]("--------------\n");
[Link]("ENTER THE FIRST VALUE:\n");
c=[Link]([Link]());
[Link]("ENTER THE SECOND VALUE:\n");
c1=[Link]([Link]());
[Link](c,c1);
break;
default:
[Link]("DOES NOT MATCH");
}
[Link]("DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO\
n");
x=[Link]([Link]());
}
while(x==1);
}
}
PACKAGE: (Save this file as [Link])
package arith;
public class operation
{
int z;
public void add(int x,int y)
{
z=x+y;
[Link]("ADDITION IS="+z);
}
public void sub(int x,int y)
{
z=x-y;
[Link]("SUBTRACTION IS="+z);
}
public void mul(int x,int y)
{
z=x*y;
[Link]("MULTIPLICATION IS="+z);
}
public void div(double x,double y)
{
double z1;
z1=x/y;
[Link]("DIVISION IS="+z1);
}
}
OUTPUT:
C:\Users\Admin>d:
D:\>cd it java
D:\it java>cd arith
D:\it java\arith>set path="d:\jdk1.5.0\bin"
D:\it java\arith>javac [Link]
D:\it java\arith>cd..
D:\it java>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\it java>java arithm
ARITHMETIC OPERATION
---------------------------------------
[Link]
[Link]
[Link]
[Link]
ENTER YOUR CHOICE:
1
ADDITION
-----------------
ENTER THE FIRST VALUE:
55
ENTER THE SECOND VALUE:
66
ADDITION IS=121
DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO
1
ENTER YOUR CHOICE:
2
SUBTRACTION
----------------------
ENTER THE FIRST VALUE:
45
ENTER THE SECOND VALUE:
12
SUBTRACTION IS=33
DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO
1
ENTER YOUR CHOICE:
3
MULTIPLICATION
---------------------------
ENTER THE FIRST VALUE:
5
ENTER THE SECOND VALUE:
6
MULTIPLICATION IS=30
DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO
1
ENTER YOUR CHOICE:
4
DIVISION
--------------
ENTER THE FIRST VALUE:
56
ENTER THE SECOND VALUE:
12
DIVISION IS=4.666666666666667
DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO
1
ENTER YOUR CHOICE:
5
DOES NOT MATCH
DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO
0
D:\it java>
RESULT:
Thus the above java program was executed and the output was
verified successfully.
Ex. No:
13
DIGITAL CLOCK
Date:27/0
3/23
AIM:
To write a java program for Digital Clock using Applet and
Thread.
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="Digital" width="200" height="200"></applet>*/
public class Digital extends Applet implements Runnable
{
Thread t;
public void start()
{
t=new Thread(this);
[Link]();
}
public void run()
{
try
{
for(;;)
{
repaint();
[Link](1000);
}
}
catch(InterruptedException e)
{
[Link]("Error");
}
}
public void paint(Graphics g)
{
showStatus("WELCOME TO DIGITAL CLOCK");
setBackground([Link]);
setForeground([Link]);
Date d=new Date();
[Link](new Font("Times New Roman",[Link],30));
[Link]([Link]()+":"+[Link]()
+":"+[Link](),600,300);
}
}
OUTPUT:
RESULT:
Thus the above java program digital clock using applet and thread was
executed and the output was verified successfully.
Ex. No:
14
Date:31/0
HUMAN FACE
3/23
AIM:
To write a java program for Human Face using Applet.
PROGRAM:
import [Link].*;
import [Link].*;
/*<applet code="Face" width="400" height="400"></applet>*/
public class Face extends Applet
{
public void paint(Graphics g)
{
showStatus("Drawing Human Face");
setBackground([Link]);
setForeground([Link]);
[Link]("Drawing Human Face",120,20);
[Link](40,40,120,150);
[Link](57,75,30,20);
[Link](110,75,30,20);
[Link](68,81,10,10);
[Link](121,81,10,10);
[Link](85,100,30,30);
[Link](60,125,80,40,180,180);
[Link](25,92,15,30);
[Link](160,92,15,30);
}
}
OUTPUT:
RESULT:
Thus the above java program Human Face using Applet was executed
and the output was verified successfully.
Ex. No: 15 SCROLLING TEXT
USING APPLET AND
Date:01/04
/23 THREAD
AIM:
To write a java program for Scrolling Text Using Applet and
Thread.
PROGRAM:
import [Link].*;
import [Link].*;
/*<applet code="Scroll" width="200" height="200"></applet>*/
public class Scroll extends Applet implements Runnable
{
Thread t;
char c;
String s;
public void start()
{
s="SCROLLING TEXT USING APPLET AND THREAD";
t=new Thread(this);
[Link]();
}
public void run()
{
try
{
for(;;)
{
repaint();
[Link](1000);
c=[Link](0);
s=[Link](1)+c;
}
}
catch(InterruptedException e)
{
[Link]("Error");
}
}
public void paint(Graphics g)
{
showStatus("SCROLLING TEXT USING APPLET AND THREAD");
setBackground([Link]);
setForeground([Link]);
[Link](new Font("Monotype corsiva",[Link],30));
[Link](s,400,400);
}
}
OUTPUT:
RESULT:
Thus the above java program Scrolling Text using Applet was
executed and the output was verified successfully.
Ex. No: 16
CHANGE
Date:11/04 BACKGROUND
/23
COLOR
AIM:
To write a java program for to Change the Back Ground Color
using Applet.
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="color" width="400" height="300"></applet>*/
public class color extends Applet implements AdjustmentListener
{
Scrollbar r,g,b;
TextField ta;
public void init()
{
setLayout(null);
r=new Scrollbar(0,0,1,0,256);
[Link](100,120,200,30);
g=new Scrollbar(0,0,1,0,256);
[Link](100,150,200,30);
b=new Scrollbar(0,0,1,0,256);
[Link](100,180,200,30);
ta=new TextField(50);
[Link](100,10,200,100);
add(r);
add(g);
add(b);
add(ta);
[Link](this);
[Link](this);
[Link](this);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
int cr,cg,cb;
cr=[Link]();
cg=[Link]();
cb=[Link]();
showStatus("Color is-->r="+cr+",g="+cg+",b="+cb);
[Link](new Color(cr,cg,cb));
}
}
OUTPUT:
RESULT:
Thus the above java program for to Change the Background
Color using Applet was executed and the output was verified successfully.
Ex. No:
LABEL COMPONENTS
Date:12/04
AIM:
To write a java program for Label Components using Applet.
PROGRAM:
import [Link].*;
import [Link].*;
//<applet code="[Link]" width=500 height="500"></applet>
public class image extends JApplet
{
JLabel j1,j2,j3;
public void init()
{
Container c =getContentPane();
[Link](new FlowLayout());
j1=new JLabel("first",new ImageIcon("[Link]"),[Link]);
add(j1);
j2=new JLabel("second",new ImageIcon("[Link]"),[Link]);
add(j2);
j3=new JLabel("third",new ImageIcon("[Link]"),[Link]);
add(j3);
}
}
OUTPUT:
RESULT:
Thus the above java program for to display the Images
using Applet was executed and the output was verified successfully.