0% found this document useful (0 votes)
10 views67 pages

Java Spiral

This document is a record notebook for the Department of Information Technology at Devanga Arts College, detailing practical work for the JAVA PROGRAMMING subject. It includes a list of exercises with their corresponding dates, aims, programs, outputs, and results for various Java programming tasks such as calculating the sum of digits, checking for Armstrong numbers, and executing Windows applications. The document serves as a certification of the practical work completed by students for their examination in April 2022.

Uploaded by

M.Anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views67 pages

Java Spiral

This document is a record notebook for the Department of Information Technology at Devanga Arts College, detailing practical work for the JAVA PROGRAMMING subject. It includes a list of exercises with their corresponding dates, aims, programs, outputs, and results for various Java programming tasks such as calculating the sum of digits, checking for Armstrong numbers, and executing Windows applications. The document serves as a certification of the practical work completed by students for their examination in April 2022.

Uploaded by

M.Anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 67

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 B.Sc. (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
EX.NO. 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 java.io.*;
import java.lang.*;
class sum
{
public static void main(String args[])throws IOException
{
DataInputStream d= new DataInputStream(System.in);
int a,s=0,r;
System.out.println("\t SUM OF DIGIT\n");
System.out.println("\t-------------\n");
System.out.println("Enter the Value:");
a=Integer.parseInt(d.readLine());
while(a>0)
{
r=a%10;
s=s+r;
a=a/10;
}
System.out.println("The result is=" +s);
}
}

OUTPUT:

D:\jdk1.5.0_05\bin>javac sum.java
Note: sum.java 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 java.io.*;
class arms
{
public static void main(String args[])throws IOException
{
int n,i,p,n1,r,b;
{
DataInputStream d= new DataInputStream(System.in);
System.out.println("\t ARMSTRONG NUMBER\n");
System.out.println("\t ****************\n");
System.out.println("Enter the Value:");
n=Integer.parseInt(d.readLine());
n1=n;
p=0;
while(n!=0)
{
r=n%10;
p=p+(r*r*r);
n=n/10;
}
if(p==n1)
System.out.println(n1+"is a Armstrong Number");
else
System.out.println(n1+" is not Armstrong Number");
}
}
}

OUTPUT:
D:\jdk1.5.0_05\bin>javac arms.java
Note: arms.java 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 java.io.*;
class prime
{
public static void main(String args[])throws IOException
{
int n,i,p,a;
DataInputStream d= new DataInputStream(System.in);
System.out.println("\tPRIME NUMBER\n");
System.out.println("\t************\n");
System.out.println("\tEnter the Value:\n");
n=Integer.parseInt(d.readLine());
p=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
p=p+1;
}
if(p==1)
System.out.println(n+" is Neither Prime nor Composite");
else if(p==2)
System.out.println(n+"is a Prime Number");
else
System.out.println(n+"is not a Prime Number");
}
}

OUTPUT:
D:\jdk1.5.0_05\bin>javac prime.java
Note: prime.java 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 java.io.*;
class rev
{
public static void main(String args[])throws IOException
{
String s,s1;
DataInputStream str= new DataInputStream(System.in);
System.out.println("\tREVERSE WITH PALINDROME\n");
System.out.println("\t**********************\n");
System.out.println("Enter the String:");
s=str.readLine();
StringBuffer sb=new StringBuffer(s);
sb.reverse();
s1=sb.toString();
System.out.println("The Reverse String is:"+sb);
if(s1.equals(s))
{
System.out.println("The string is Palidrome");
}
else
{
System.out.println("The string is Not Palidrome");
}
}
}

OUTPUT:
D:\jdk1.5.0_05\bin>javac rev.java
Note: rev.java 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 java.io.*;
import java.lang.Math;
class area1
{
public static void main(String args[])throws IOException
{
int x,ch,b1,h;
String a;
double r,l,b;
System.out.println("\t\tAREA CALCULATION");
System.out.println("\t\t-----------------");
DataInputStream d=new DataInputStream(System.in);
System.out.println("1.CIRCLE \n2.TRAINGLE \n3.RECTANGLE");
shape s1=new shape();
do
{
System.out.println("Enter your choice:");
ch=Integer.parseInt(d.readLine());
switch(ch)
{
case 1:
System.out.println("AREA OF CIRCLE");
System.out.println("------------------");
System.out.println("ENTER THE RADIOUS VALUE");
r=Double.parseDouble(d.readLine());
System.out.println("THE ANSWER IS");
s1.add(r);
break;
case 2:
System.out.println("AREA OF TRAINGLE");
System.out.println("------------------");
System.out.println("ENTER THE BASE AND HEIGHT VALUE");
b1=Integer.parseInt(d.readLine());
h=Integer.parseInt(d.readLine());
System.out.println("THE ANSWER IS");
s1.add(b1,h);
break;
case 3:
System.out.println("AREA OF RECTANGLE");
System.out.println("------------------");
System.out.println("ENTER THE LENGTH AND BREATH VALUE");
l=Integer.parseInt(d.readLine());
b=Integer.parseInt(d.readLine());
System.out.println("THE ANSWER IS");
s1.add(l,b);
break;
default:
System.out.println("DOES NOT MATCH");
}
System.out.println("DO U WANT TO CONTINUE PRSS 1 FOR YES 0 FOR NO");
x=Integer.parseInt(d.readLine());
}while(x==1);
}
}
class shape
{
double c,re,t;
void add(double x)
{
c=3.14*x*x;
System.out.println("AREA OF CIRCLE IS="+c);
}
void add(int y,int z)
{
t=0.5*y*z;
System.out.println("AREA OF TRAINGLE IS="+t);
}
void add(double l1,double l2)
{
re=l1*l2;
System.out.println("AREA OF RECTANGLE IS="+re);
}
}

OUTPUT:
D:\jdk1.5.0_05\bin>javac area1.java
Note: area1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\jdk1.5.0_05\bin>java area1
AREA CALCULATION
--------------------------------
1.CIRCLE
2.TRAINGLE
3.RECTANGLE
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 java.io.*;
class comp
{
public static void main(String args[])throws IOException
{
int r,r1,i,i1,x,y;
System.out.println("\t\tCOMPLEX ADDITION");
System.out.println("\t\t-----------------");
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter the First Real and Imaginary Number:");
r=Integer.parseInt(d.readLine());
i=Integer.parseInt(d.readLine());
System.out.println("Enter the Second Real and Imaginary Number:");
r1=Integer.parseInt(d.readLine());
i1=Integer.parseInt(d.readLine());
x=r+r1;
y=i+i1;
System.out.println("THE ANSWER IS:");
if(y==0)
System.out.println(x);
else
{
if(x==0)
System.out.println(+y+"i");
else
{
if(y>0)
System.out.println("\t"+x+"+i"+y);
else
System.out.println("\t"+x+"-i"+(-y));
}
}
}
}

OUTPUT:
D:\jdk1.5.0\bin>javac comp.java
Note: comp.java 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 java.io.*;
import java.lang.* ;
class win
{
public static void main(String args[])throws IOException
{
int ch;
DataInputStream ob=new DataInputStream(System.in);
do
{
System.out.println("*********************************************");
System.out.println("Executing Various Windows Application");
System.out.println("*********************************************");
System.out.println("\n 1-Notepad\n 2-Paint\n 3-Calculator\n 4-Explorer\n 5-
Exit\n");
Runtime r=Runtime.getRuntime();
Process p=null;
System.out.print("Enter your choice:");
ch=Integer.parseInt(ob.readLine());
switch(ch)
{
case 1:
try
{
p=r.exec("notepad.exe");
System.out.println("Notepad is opened");
}
catch(Exception e)
{
System.out.println("\n Error in Notepad");
}
break;
case 2:
try
{
p=r.exec("mspaint.exe");
System.out.println("Paint is Opened");
}
catch(Exception e)
{
System.out.println("Error in paint");
}
break;
case 3:
try
{
p=r.exec("calc.exe");
System.out.println("Calculator is opened");
}
catch(Exception e)
{
System.out.println("\n Error in Calculator");
}
break;
case 4:
try
{
p=r.exec("explorer.exe");
System.out.println("Explorer is opened");
}
catch(Exception e)
{
System.out.println("\n Error in Exception");
}
break;
case 5:
System.out.println("Exit the program");
System.exit(0);
default:
System.out.println("Invalid Choice");
break;
}
}
while(ch!=5);
}
}

OUTPUT:
D:\jdk1.5.0\bin>javac win.java
Note: win.java 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 java.io.*;
class filecopy
{
public static void main(String args[])throws IOException
{
int i;
String src,des;
DataInputStream ob=new DataInputStream(System.in);
System.out.print("Enter the Source File Name:");
src=ob.readLine();
System.out.print("Enter the Destination File Name:");
des=ob.readLine();
try
{
FileInputStream fin=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(des);
do
{
i=fin.read();
if(i!=-1)
{
System.out.print((char)i);
fos.write(i);
}
}
while(i!=-1);
System.out.println("\nSource File: "+src+" is Successfully Copied to
Destination File:"+des);
}
catch(IOException e)
{
System.out.println("\nFile Error"+e);
}
}
}
OUTPUT:

D:\jdk1.5.0\bin>javac filecopy.java
Note: filecopy.java 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:file.txt
Enter the Destination File Name:output.txt
1.CLASS
2.OBJECT
3.INHERITANCE
4.APPLET
5.JAVA
Source File: file.txt is Successfully Copied to Destination File:output.txt
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 java.io.*;
class strfn
{
public static void main(String args[])throws IOException
{
String s1,s2;
int st,ed,p,ch;
DataInputStream ob=new DataInputStream(System.in);
do
{
System.out.println("\n******************");
System.out.println("String Function");
System.out.println("******************");
System.out.println("\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");
System.out.println("Enter your choice:");
ch=Integer.parseInt(ob.readLine());
switch(ch)
{
case 1:
System.out.println("Enter any String:");
s1=ob.readLine();
System.out.println("\n \tStringLength is:"+s1.length());
break;
case 2:
System.out.println("Enter any string:");
s1=ob.readLine();
System.out.print("Enter the Position:");
p=Integer.parseInt(ob.readLine());
System.out.println("\n \tCharacter is:"+s1.charAt(p));
break;
case 3:
System.out.print("Enter any String:");
s1=ob.readLine();
System.out.print("Enter the Starting position:");
st=Integer.parseInt(ob.readLine());
System.out.print("Enter the ending Position:");
ed=Integer.parseInt(ob.readLine());
System.out.println("\n \tSubString is :"+s1.substring(st,ed));
break;
case 4:
System.out.print("Enter 1st String:");
s1=ob.readLine();
System.out.print("Enter 2nd String:");
s2=ob.readLine();
if(s1.equals(s2))
System.out.println("\n \tBoth String are Equal");
else
System.out.println("\n \tBoth String are not Equal");
case 5:
System.out.print("Enter 1st String:");
s1=ob.readLine();
System.out.print("Enter 2nd String:");
s2=ob.readLine();
if(s1.equalsIgnoreCase(s2))
System.out.println("\n \tBoth String are Equal");
else
System.out.println("\n \tBoth String are not Equal");
break;
case 6:
System.out.print("Enter any String:");
s1=ob.readLine();
s2=s1.replace('a','e');
System.out.println("\n \tAfter Replacement is:"+s2);
break;
case 7:
System.out.print("Enter 1st String:");
s1=ob.readLine();
System.out.print("Enter 2nd String:");
s2=ob.readLine();
System.out.println("\n \tConcatenation of String is:"+s1.concat(s2));
break;
case 8:
System.out.print("Enter any String:");
s1=ob.readLine();
System.out.println("\n \tTrimmed String is:"+s1.trim());
break;
case 9:
System.out.print("Enter any String:");
s1=ob.readLine();
System.out.println("\n \tUpperCase String is:"+s1.toUpperCase());
break;
case 10:
System.out.print("Enter any String:");
s1=ob.readLine();
System.out.println("\n \tLowerCase String is:"+s1.toLowerCase());
break;
case 11:
System.out.print("Enter any String:");
s1=ob.readLine();
StringBuffer sb=new StringBuffer(s1);
System.out.println("\n \tReverse String is:"+sb.reverse());
break;
case 12:
System.out.print("Enter any String:");
s1=ob.readLine();
s2=s1;
System.out.println("\n \tCopied String is:"+s2);
break;
case 13:
System.out.println("Exit the program");
System.exit(0);
default:
System.out.println("Invalid Choice");
break;
}
}
while(ch!=13);
}
}

OUTPUT:
D:\jdk1.5.0\bin>javac strfn.java
Note: strfn.java 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 java.io.*;
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(System.in);
System.out.println("\n\t\t*********************");
System.out.println("\t\tMATRIX MULTIPLICATION");
System.out.println("\t\t*********************");
System.out.println("Enter the number of rows and columns of first matrix:");
m=Integer.parseInt(ob.readLine());
n=Integer.parseInt(ob.readLine());
System.out.println("Enter the number of rows and columns of second
matrix:");
p=Integer.parseInt(ob.readLine());
q=Integer.parseInt(ob.readLine());
if (n!=p)
{
System.out.println("\n MATRIX MULTIPLICATION CANNOT PERFORMED");
System.exit(0);
}
else
{
a=new int[m][n];
b=new int[p][q];
c=new int[m][q];
System.out.println("Enter the element of first matrix:");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=Integer.parseInt(ob.readLine());
System.out.println("Enter the elements of second matrix:");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
b[i][j]=Integer.parseInt(ob.readLine());
System.out.println("FIRST MATRIX IS:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
System.out.println("SECOND MATRIX IS:");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println();
}
System.out.println("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;
System.out.print(c[i][j]+"\t");
sum=0;
}
System.out.println("\n");
}
}
}
}

D:\jdk1.5.0\bin>javac matmul.java
Note: matmul.java 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 java.io.*;
class sorting
{
public static void main(String args[])throws IOException
{
int k[]=new int[10],n,i,j,t;
System.out.println("\tSORTING NUMBER");
System.out.println("\t-----------------------");
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter Array Size:");
n=Integer.parseInt(d.readLine());
System.out.println("Enter the Numbers:");
for(i=0;i<n;i++)
{
k[i]=Integer.parseInt(d.readLine());
}
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;
}
System.out.println("ASCENDING ORDER:");
for(i=0;i<n;i++)
System.out.println(k[i]+"\n");
}
}
OUTPUT:
D:\jdk1.5.0\bin>javac sorting.java
Note: sorting.java 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 java.io.*;
import arith.*;
class arithm
{
public static void main(String args[])throws IOException
{
String s;
int a,b,x,ch;
double c,c1;
System.out.println("ARITHMETIC OPERATION\n");
System.out.println("-----------------------------------\n");
System.out.println("1.ADDITION\n2.SUBTRACTION\n3.MULTIPLICATION\
n4.DIVISION");
DataInputStream d=new DataInputStream(System.in);
operation o=new operation();
do
{
System.out.println("ENTER YOUR CHOICE:\n");
ch=Integer.parseInt(d.readLine());
switch(ch)
{
case 1:
System.out.println("ADDITION\n");
System.out.println("--------------\n");
System.out.println("ENTER THE FIRST VALUE:\n");
a=Integer.parseInt(d.readLine());
System.out.println("ENTER THE SECOND VALUE:\n");
b=Integer.parseInt(d.readLine());
o.add(a,b);
break;
case 2:
System.out.println("SUBTRACTION\n");
System.out.println("--------------\n");
System.out.println("ENTER THE FIRST VALUE:\n");
a=Integer.parseInt(d.readLine());
System.out.println("ENTER THE SECOND VALUE:\n");
b=Integer.parseInt(d.readLine());
o.sub(a,b);
break;
case 3:
System.out.println("MULTIPLICATION\n");
System.out.println("--------------\n");
System.out.println("ENTER THE FIRST VALUE:\n");
a=Integer.parseInt(d.readLine());
System.out.println("ENTER THE SECOND VALUE:\n");
b=Integer.parseInt(d.readLine());
o.mul(a,b);
break;
case 4:
System.out.println("DIVISION\n");
System.out.println("--------------\n");
System.out.println("ENTER THE FIRST VALUE:\n");
c=Integer.parseInt(d.readLine());
System.out.println("ENTER THE SECOND VALUE:\n");
c1=Integer.parseInt(d.readLine());
o.div(c,c1);
break;
default:
System.out.println("DOES NOT MATCH");
}
System.out.println("DO U WANT TO CONTINUE PRESS 1 FOR YES 0 FOR NO\
n");
x=Integer.parseInt(d.readLine());
}
while(x==1);
}
}

PACKAGE: (Save this file as Operation.java)

package arith;
public class operation
{
int z;
public void add(int x,int y)
{
z=x+y;
System.out.println("ADDITION IS="+z);
}
public void sub(int x,int y)
{
z=x-y;
System.out.println("SUBTRACTION IS="+z);
}
public void mul(int x,int y)
{
z=x*y;
System.out.println("MULTIPLICATION IS="+z);
}
public void div(double x,double y)
{
double z1;
z1=x/y;
System.out.println("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 operation.java
D:\it java\arith>cd..
D:\it java>javac arithm.java
Note: arithm.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
D:\it java>java arithm
ARITHMETIC OPERATION
---------------------------------------
1.ADDITION
2.SUBTRACTION
3.MULTIPLICATION
4.DIVISION
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 java.applet.*;
import java.awt.*;
import java.util.*;
/*<applet code="Digital" width="200" height="200"></applet>*/
public class Digital extends Applet implements Runnable
{
Thread t;
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
try
{
for(;;)
{
repaint();
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.print("Error");
}
}
public void paint(Graphics g)
{
showStatus("WELCOME TO DIGITAL CLOCK");
setBackground(Color.pink);
setForeground(Color.red);
Date d=new Date();
g.setFont(new Font("Times New Roman",Font.BOLD,30));
g.drawString(d.getHours()+":"+d.getMinutes()
+":"+d.getSeconds(),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 java.awt.*;
import java.applet.*;
/*<applet code="Face" width="400" height="400"></applet>*/
public class Face extends Applet
{
public void paint(Graphics g)
{
showStatus("Drawing Human Face");
setBackground(Color.pink);
setForeground(Color.blue);
g.drawString("Drawing Human Face",120,20);
g.drawOval(40,40,120,150);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
g.drawOval(85,100,30,30);
g.fillArc(60,125,80,40,180,180);
g.drawOval(25,92,15,30);
g.drawOval(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 java.applet.*;
import java.awt.*;
/*<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);
t.start();
}
public void run()
{
try
{
for(;;)
{
repaint();
Thread.sleep(1000);
c=s.charAt(0);
s=s.substring(1)+c;
}
}
catch(InterruptedException e)
{
System.out.print("Error");
}
}
public void paint(Graphics g)
{
showStatus("SCROLLING TEXT USING APPLET AND THREAD");
setBackground(Color.pink);
setForeground(Color.red);
g.setFont(new Font("Monotype corsiva",Font.BOLD,30));
g.drawString(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 java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<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);
r.setBounds(100,120,200,30);
g=new Scrollbar(0,0,1,0,256);
g.setBounds(100,150,200,30);
b=new Scrollbar(0,0,1,0,256);
b.setBounds(100,180,200,30);
ta=new TextField(50);
ta.setBounds(100,10,200,100);
add(r);
add(g);
add(b);
add(ta);
r.addAdjustmentListener(this);
g.addAdjustmentListener(this);
b.addAdjustmentListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
int cr,cg,cb;
cr=r.getValue();
cg=g.getValue();
cb=b.getValue();
showStatus("Color is-->r="+cr+",g="+cg+",b="+cb);
ta.setBackground(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 javax.swing.*;
import java.awt.*;
//<applet code="image.class" width=500 height="500"></applet>
public class image extends JApplet
{
JLabel j1,j2,j3;
public void init()
{
Container c =getContentPane();
c.setLayout(new FlowLayout());
j1=new JLabel("first",new ImageIcon("child1.jpg"),JLabel.CENTER);
add(j1);
j2=new JLabel("second",new ImageIcon("child2.jpg"),JLabel.CENTER);
add(j2);
j3=new JLabel("third",new ImageIcon("child3.jpg"),JLabel.CENTER);
add(j3);
}
}

OUTPUT:
RESULT:
Thus the above java program for to display the Images
using Applet was executed and the output was verified successfully.

You might also like