Java Practicals
Java Practicals
Java Practicals
PART-A
EXNO.1
PROGRAM
import java.util.Scanner;
celsius= scan.nextInt();
OUTPUT
EXNO.2
PROGRAM
import java.util.Scanner;
int num1,num2,largest;
num1= scan.nextInt();
num2= scan.nextInt();
largest= num1;
else
largest= num2;
System.out.print("\nlargest" + largest);
OUTPUT:
EXNO.3.
PROGRAM
import java.util.Scanner;
int i, fact=1,n;
n= scan.nextInt();
for(i=1;i<n;i++)
fact=fact*i;
OUTPUT
EXNO.4
PROGRAM
import java.util.*;
class vect
{
public static void main(String args[])
int i,delete,n;
Vector<Integer>v=new Vector<Integer>();
n= sc.nextInt();
for(i=0;i<n;i++)
v.add(sc.nextInt());
delete=sc.nextInt();
boolean x=v.removeElement(delete);
if(x== true)
for(i=0;i<v.size();i++)
System.out.println(v.elementAt(i)+"");
else
}
}
OUTPUT
EXNO.5
PROGRAM
import java.util.Scanner;
String str,rev="";
System.out.println("Enter a String");
str=sc.nextLine();
int length=str.length();
for(int i=length-1;i>=0;i--)
rev=rev+str.charAt(i);
if(str.equals(rev))
System.out.println(str+" is palindrome");
else
OUTPUT:
EXNO.6
PROGRAM
import java.util.Scanner;
import java.io.*;
class student
int regno,total=0,subjects;
String name;
int marks[];
student()
System.out.println("Enter regno");
regno=scan.nextInt();
System.out.println("Enter name");
name=scan.next();
getdismarks();
marks[0]= scan.nextInt();
marks[1]= scan.nextInt();
marks[2]= scan.nextInt();
for(int i=0;i<3;i++)
total= marks[i];
class classcreation
{
for(int i=0;i<3;i++)
OUTPUT
EXNO.7
PROGRAM
import java.util.Scanner;
import java.io.*;
class area
{
int r;
double pi=3.14,area;
r=s.nextInt();
area= pi*r*r;
OUTPUT
EXNO.8
PROGRAM
class car
public car()
System.out.println("class car");
}
public void vehicleType()
System.out.println("Vehicle Type:Car");
maruti()
System.out.println("class Maruti");
System.out.println("Brand: Maruti");
System.out.println("Max:90kmph");
public multilevel()
{
System.out.println("Max :80kmph");
m1.vehicleType();
m1.brand();
m1.speed();
OUTPUT
EXNO.9
PROGRAM
import java.io.*;
import java.util.*;
myexception(String s)
super(s);
class pgm9
try
System.out.println("enter no.");
if(num<1 || num>100)
else
catch(myexception e)
{
OUTPUT:
EXNO.10
PROGRAM
import java.util.*;
import java.io.*;
class mythread1 extends Thread
int i;
try
for(i=0;i<5;i++)
System.out.println("hello");
sleep(2000);
catch(Exception e)
System.out.println(e);
int i;
try
{
for(i=0;i<5;i++)
System.out.println("Gud morning");
sleep(2000);
catch(Exception e)
System.out.println(e);
int i;
try
for(i=0;i<5;i++)
System.out.println("welcome");
sleep(2000);
catch(Exception e)
{
System.out.println(e);
class threadprogram
obj1.start();
obj2.start();
obj3.start();
OUTPUT
EXNO.11
PROGRAM
import java.io.FileOutputStream;
import java.io.IOException;
class filecreation
{
try
byte b[]=s.getBytes();
fout.write(b);
fout.close();
catch(IOException e)
System.out.println(e);
OUTPUT
EXNO.12
PROGRAM
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public mouse()
setSize(500,400);
add(label);
addMouseMotionListener(this);
setVisible(true);
OUTPUT
EXNO.13
PROGRAM
import java.applet.Applet;
import java.awt.*;
g.drawString("Line",100,100);
g.setColor(Color.red);
g.drawLine(30,100,10,10);
g.setColor(Color.magenta);
g.drawRect(30,50,20,30);
g.setColor(Color.yellow);
g.fillRect(30,50,20,30);
g.drawString("Rectangle",300,400);
/*<html>
</applet>
</html>*/
OUTPUT
EXNO.14
PROGRAM
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextField(10);
b1 = new Button("+\n");
b2 = new Button("-");
b3 = new Button("*");
b4 = new Button("/");
b5 = new Button("1");
b6 = new Button("2");
b7 = new Button("3");
b8 = new Button("4");
b9 = new Button("5");
add(t1);
add(t2);
add(t3);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b10);
add(b11);
add(b12);
add(b13);
add(b14);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String s1 = t1.getText();
String s2 = t2.getText();
double a = Double.parseDouble(s1);
double b = Double.parseDouble(s2);
if (ae.getSource() == b1) {
t3.setText(String.valueOf(a + b));
t3.setText(String.valueOf(a - b));
t3.setText(String.valueOf(a * b));
t3.setText(String.valueOf(a / b));
/*
</applet>
*/