JAVA 23343
JAVA 23343
DATE:20/12/2024
AIM:
CODING:
import java.util.Scanner;
class Circle
{
static int a,s,r;
static double c;
Circle()
{
Scanner y=new Scanner(System.in);
System.out.println("Enter a Value:");
a=y.nextInt();
s=a*a;
System.out.println("Area of square:"+s);
}
Circle(int r)
{
c=3.14*r*r;
System.out.println("Area of Circle:"+c);
}
public static void main(String[] args)
{
Scanner z=new Scanner(System.in);
System.out.println("Area Calculation:");
System.out.println("1.Square");
System.out.println("2.Circle");
int ch;
System.out.println("Enter a Choice:");
ch=z.nextInt();
switch(ch)
{
case 1:
new Circle();
break;
case 2:
System.out.println("Enter r Value:");
r=z.nextInt();
new Circle(r);
break;
default:
System.out.println("Invalid:");
break;
}
}
}
OUTPUT :
D:\23343>javac Circle.java
D:\23343>java Circle
Area Calculation:
1.Square
2.Circle
Enter a Choice:
1
Enter a Value:
2
Area of square:4
Area Calculation:
1.Square
2.Circle
Enter a Choice:
2
Enter r Value:
5
Area of Circle:78.5
RESULT:
Thus, the above program was executed successfully and output was verified.
EX.NO:2 OVERLOADING METHOD
DATE:28/12/2024
AIM :
CODING:
import java.util.Scanner;
public class mo
{
static void per(int a,int b,int c)
{
int tri;
tri=a+b+c;
System.out.println("Perimeter Of Triangle:"+tri);
}
static void per(double r)
{
double cir;
cir=2*3.14*r;
System.out.println("Perimeter Of Circle:"+cir);
}
public static void main(String[] args)
{
Scanner z=new Scanner(System.in);
System.out.println("Perimeter Calculation:");
System.out.println("1.Triangle");
System.out.println("2.Circle");
int ch;
System.out.println("Enter a Choice:");
ch=z.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter a Value:");
int a=z.nextInt();
System.out.println("Enter b Value:");
int b=z.nextInt();
System.out.println("Enter c Value:");
int c=z.nextInt();
per(a,b,c);
break;
case 2:
System.out.println("Enter r Value:");
double r=z.nextDouble();
per(r);
break;
default:
System.out.println("Invalid:");
break;
}
}}
OUTPUT:
D:\23343>javac mo.java
D:\23343>java mo
Perimeter Calculation:
1.Triangle
2.Circle
Enter a Choice:
1
Enter a Value:
3
Enter b Value:
7
Enter c Value:
8
Perimeter Of Triangle:18
Perimeter Calculation:
1.Triangle
2.Circle
Enter a Choice:
2
Enter r Value:
4
Perimeter Of Circle:25.12
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:3 OVERRIDING METHOD
DATE:06/01/2025
AIM:
CODING:
import java.util.Scanner;
class A
{
String co;
Scanner x=new Scanner(System.in);
void get()
{
System.out.println("Enter Country Name:");
co=x.nextLine();
}
}
class B extends A
{
String pl;
int jer;
void get()
{
super.get();
System.out.println("Enter Player Name:");
pl=x.nextLine();
System.out.println("Enter Jersey Number:");
jer=x.nextInt();
}
void display()
{
System.out.println("Country Name:"+ co);
System.out.println("Player Name:"+pl);
System.out.println("Jersey Number:"+ jer);
}
}
D:\23343>javac mor.java
D:\23343>java mor
INDIA
DHONI
Jersey Number:7
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:4 ONE-DIMENSIONAL ARRAY
DATE:13/01/2025
AIM:
CODING:
import java.util.Scanner;
public class array
{
public static int linearsearch(int[] arr,int target)
{
for(int i=0;i<arr.length;i++)
{
if(arr[i]==target)
{
return i;
}
}
return -1;
}
}
}
OUTPUT:
D:\23343>javac array.java
D:\23343>java array
RESULT:
Thus, the above program was executed successfully and output was verified
EX NO:5 TWO-DIMENSIONAL ARRAY
DATE:23/01/2025
AIM:
CODING:
import java.util.Scanner;
public class tarray
{
public static void main(String[] args)
{
Scanner z=new Scanner(System.in);
System.out.println("Enter the number of rows:");
int r=z.nextInt();
System.out.println("Enter the number of columns:");
int c=z.nextInt();
int a[][]=new int[r][c];
int b[][]=new int[r][c];
int re[][]=new int[r][c];
System.out.println("Enter First Matrix Elements:");
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
a[i][j]=z.nextInt();}}
System.out.println("Enter Second matrix Elements:");
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
b[i][j]=z.nextInt();
}
}
System.out.println("Addition Of Matrix:");
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
re[i][j]=a[i][j]+b[i][j];
}
}
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
System.out.print(re[i][j]+" ");
}
System.out.println();
}
}
}
OUTPUT:
D:\23343>javac tarray.java
D:\23343>java tarray
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:6 STRING MANIPULATION
DATE:30/01/2025
AIM:
CODING:
import java.util.Scanner;
public class str
{
public static void main(String[] args)
{
String a,b;
Scanner z=new Scanner(System.in);
System.out.println("Enter first string:");
a=z.nextLine();
System.out.println("Enter Second string:");
b=z.nextLine();
char[] A= a.toCharArray();
char[] B= b.toCharArray();
System.out.println("Length of First String:"+A.length);
System.out.println("Length of Second String:"+B.length);
char[] C=new char[A.length+B.length];
for(int i=0;i<A.length;i++)
{
C[i]=A[i];
}
for(int i=0;i<B.length;i++)
{
C[A.length+i]=B[i];
}
String c=new String(C);
System.out.println("Concatenation of Strings: "+c);
D:\23343>javac str.java
D:\23343>java str
Raj
kumar
Character at position 2: j
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:7 INTERFACE
DATE:06/02/2025
AIM:
CODING:
import java.util.Scanner;
interface A
{
void t1 ();
}
interface B extends A
{
void t2();
}
class cri implements B
{
public void t1()
{
Scanner z=new Scanner(System.in);
System.out.println("Team 1:");
System.out.println("Enter a Team Name:");
String a=z.nextLine();
System.out.println("Enter a Captain Name:");
String b=z.nextLine();
System.out.println("Team Name:"+a);
System.out.println("Captain Name:"+b);
}
public void t2()
{
Scanner z=new Scanner(System.in);
System.out.println("Team 2:");
System.out.println("Enter a Team Name:");
String a=z.nextLine();
System.out.println("Enter a Captain Name:");
String b=z.nextLine();
System.out.println("Team Name:"+a);
System.out.println("Captain Name:"+b);
}
}
class in
{
public static void main(String[] args)
{
cri r=new cri();
r.t1();
r.t2();
}
}
OUTPUT:
D:\23343>javac in.java
D:\23343>java in
Team 1:
Enter a Team Name:
CSK
Enter a Captain Name:
DHONI
Team Name: CSK
Captain Name: DHONI
Team 2:
Enter a Team Name:
MI
Enter a Captain Name:
ROHIT
Team Name: MI
Captain Name: ROHIT
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:8 CREATE AND IMPORT PACKAGE
DATE:13/02/2025
AIM:
CODING:
Package Program:
package raj;
import java.util.Scanner;
public class A
System.out.println("Enter a Value:");
int a=z.nextInt();
if(a>=0)
}
else
Main Program:
import raj.A;
A r=new A();
r.pn();
}
OUTPUT:
D:\23343\raj>javac A.java
D:\23343\raj>cd D:\23343
D:\23343>javac pack.java
D:\23343>java pack
Enter a Value:
5 is Positive Number.
Enter a Value:
-8
-8 is Negative Number
RESULT:
Thus, the above program was executed successfully and output was verified.
EX.NO:9 MULTIPLE THREADS
DATE:20/02/2025
AIM:
CODING:
import java.util.*;
class table2 extends Thread
{
private int limit=10;
public void run()
{
System.out.println("Multiplication Table of 2:");
for(int i=1;i<=limit;i++)
{
System.out.println("2 x" +i+ "=" + (2*i));
}
}
}
D:\23343>javac thread.java
D:\23343>java thread
Multiplication Table of 2:
Multiplication Table of 3:
2 x1=2
2 x2=4
3 x1=3
3 x2=6
2 x3=6
2 x4=8
3 x3=9
3 x4=12
3 x5=15
3 x6=18
3 x7=21
3 x8=24
3 x9=27
2 x5=10
2 x6=12
3 x10=30
2 x7=14
2 x8=16
2 x9=18
2 x10=20
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:10 EXCEPTION HANDLING
DATE:27/02/2025
AIM:
CODING:
import java.util.Scanner;
class Exp extends Exception
{
public Exp(String message)
{
super(message);
}
}
public class EH
{
public static void main(String[] args)
{
Scanner obj = new Scanner(System.in);
try
{
System.out.println("Enter your Mark:");
int m = obj.nextInt();
if (m < 35)
{
throw new Exp("Fail");
}
System.out.println("Pass");
}
catch (Exp e)
{
System.out.println(e.getMessage());
}
catch (Exception e)
{
System.out.println("Invalid input");
}
finally
{
System.out.println("Student Mark List");
}
obj.close();
}
}
OUTPUT:
D:\23343>javac EH.java
D:\23343>java EH
Enter your Mark:
80
Pass
Student Mark List
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:11 DESIGN A WEB PAGE
DATE:28/02/2025
AIM:
CODING:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class web extends Applet implements ActionListener
{
Button home,c1,c2,contact;
String content="Welcome";
Image photo,b,s;
public void init()
{
setSize(600,400);
setBackground(Color.YELLOW);
b=getImage(getDocumentBase(),"mb.jpg");
s=getImage(getDocumentBase(),"sh.jpg");
home=new Button("HOME");
c1=new Button("BHEEM");
c2=new Button("SHINCHAN");
contact=new Button("CONTACT US");
home.addActionListener(this);
c1.addActionListener(this);
c2.addActionListener(this);
contact.addActionListener(this);
add(home);
add(c1);
add(c2);
add(contact);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==home)
{
content="WELCOME TO CARTOON NETWORK";
}
else if(e.getSource()==c1)
{
content="Mighty Little Bheem is a Netflix animated series for children
that is a spin-off of the popular Indian show Chhota Bheem.";
photo=getImage(getDocumentBase(),"mb.jpg");
}
else if(e.getSource()==c2)
{
content="Crayon Shin-chan is a Japanese manga series written and
illustrated by Yoshito Usui.";
photo=getImage(getDocumentBase(),"sh.jpg");
}
else if(e.getSource()==contact)
{
content="Contact us: Email - CN@gmail.com phone - 123-456-7890";
}
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.BLACK);
g.setFont(new Font("Arial", Font.BOLD,16));
g.drawString("Cartoon Network", 200,50);
g.setFont(new Font("Arial", Font.PLAIN, 14));
g.drawString(content, 50,100);
if(photo!=null)
{
g.drawImage(photo,250,200,850,300,this);
}
else
{
g.drawString("",50,150);
}
}
}
/*<applet code="web.class" width="600" height="400"></applet>*/
OUTPUT:
Thus, the above program was executed successfully and output was verified
EX.NO:12 MOUSE EVENT
DATE:06/03/2025
AIM:
CODING:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class mouse extends Applet implements MouseListener
{
private Color currentColor = Color.BLACK;
public void init()
{
setBackground(currentColor);
addMouseListener(this);
}
public void paint(Graphics g)
{
D:\23343>javac mouse.java
D:\23343>appletviewer mouse.java
RESULT:
Thus, the above program was executed successfully and output was verified
EX.NO:13 KEYBOARD EVENT
DATE:13/03/2025
AIM:
CODING:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
setSize(400, 400);
setBackground(bgColor);
addKeyListener(this);
setFocusable(true);
}
public void paint(Graphics g)
setBackground(bgColor);
g.setColor(Color.WHITE);
g.drawString("Press Red",20,50);
if(e.getKeyCode() == KeyEvent.VK_SHIFT)
bgColor = Color.RED;
repaint();
if(e.getKeyCode() == KeyEvent.VK_SHIFT)
bgColor =Color.GREEN;
repaint();
Text += e.getKeyChar();
if(Text.endsWith("yellow"))
bgColor=Color.YELLOW;
repaint();
</applet>*/
OUTPUT:
D:\23343>javac keybo.java
D:\23343>appletviewer keybo.java
RESULT:
Thus, the above program was executed successfully and output was verified