Java Lab
Java Lab
Cheeryal (V), Keesara (M), Ranga Reddy District – 501 301 (T.S)
JAVA PROGRAMMING
LABORATORY MANUAL
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
1
Geethanjali College of Engineering and Technology
Department of COMPUTER SCIENCE & ENGINEERING
(Name of the Lab Course) : JAVA PROGRAMMING
(JNTU CODE): A40585 Programme : UG
Prepared by : Modified by :
1) Name : N.Swapna 1) Name : A.Sri Lakshmi
2) Sign : 2) Sign :
3) Design : Asso. Prof 3) Design : Asso. Prof
4) Date : 28/11/2015 4) Date : 28/11/2015
Approved by : (HOD )
1) Name :
2) Sign :
3) Date :
2
JAVA PROGRAMMING
LAB
3
LIST OF LAB EXERCISES
1 Write a java program that works as a simple calculator. Use a grid layout to 14
arrange buttons for the digits and for the +, -, *, % operations. Add a text field
to display the result. Handle any possible exceptions like divided by zero.
b) Develop an applet that receives an integer in one text field, and computes its
factorial Value and returns it in another text field, when the button named
“Compute” is clicked.
3 Write a program that creates a user interface to perform integer divisions. The 21
user enters two numbers in the text fields, Num1 and Num2. The division of
Num1 and Num2 is displayed in the Result field when the Divide button is
clicked. If Num1 or Num2 were not an integer, the program would throw a
NumberFormatException. If Num2 were Zero, the program would throw an
ArithmeticException Display the exception in a message dialog box.
4 Write a java program that implements a multi-thread applications that has three 23
threads. First thread generates random integer every 1 second and if the value
is even, second thread computes the square of the number and prints. If the
value is odd, the thread will print the value of the number.
5 Write a java program that connects to a database using JDBC and does add, 26
6 Write a java program that simulates a traffic light. The program lets user select 28
one of the three lights: red, yellow, or, green with radio buttons. On selecting a
button, an appropriate message with “stop” initially, there is no message
shown.
7 Write a java program to create an abstract class named shape that contains two 30
integers and an empty method named printArea(). Provide three classes named
Rectangle, Triangle and Circle such that classes contains only the method
printArea() that prints the area of the given shape.
4
8 Suppose that a table named Table.txt is stored in a text file. The first line in the 32
file is the header, and the remaining lines correspond to rows in the table. The
elements are separated by commas. Write a java program to display the table
using Labels in Grid Layout.
9 Write a java program that handles all mouse events and shows the event name 34
at the center of the window when a mouse event is fired (use Adapter classes).
10 Write a java Program That loads names and phone numbers from a text file 37
where the data is organized as one line per record and each filed in a record are
separated by a tab (\t). It takes a name or phone number as input and prints the
corresponding other value from the hash table (hint: use hash tables).
12 Write a java Program that takes tab separated data (one record per line) from a 41
text file and inserts them into a database.
5
ADDITIONAL PROGRAMS
6
Vision of the Department
To produce globally competent and socially responsible computer science engineers
contributing to the advancement of engineering and technology which involves creativity and
innovation by providing excellent learning environment with world class facilities.
2. To provide graduates with analytical and problem solving skills to design algorithms,
other hardware / software systems, and inculcate professional ethics, inter-personal skills
to work in a multi-cultural team.
3. To facilitate graduates to get familiarized with the art software / hardware tools, imbibing
creativity and innovation that would enable them to develop cutting-edge technologies of
multi-disciplinary nature for societal development.
7
PROGRAM OUTCOMES
8
Mapping of Lab Course with Programme Educational Objectives
Java
Professional
1 A40585 Programming I L H H
core
Lab
POs 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Java Exp no.
Programming
CO40585.1: Student 1 ML H H M M M
gains the
knowledge about
grid layout i.e to
create a calculator
arrange buttons for
the digits for the +,
-,*, % operations
and add a text field
to display the
result.
CO40585.2: 2 a,b L M M H M M H
Student gains the
knowledge
To write
simple
applets.
Professional core
To write a
simple
Hyper Text
Markup
Language
(HTML)
9
document
to load an
applet into
an applet
container
and execute
the applet.
About five
methods
that are
called
automatical
ly by an
applet
container
during an
applet's life
cycle.
CO40585.3: Student 3,7 L M M H M M
gains the
knowledge about
Exceptions like
Arithmetic
Exception,
NumberFormatExc
eption to display
the exception in a
message dialog
box.
CO40585.4: 4 L H M H L M M
Student gains the
knowledge to
implement the
concept of multi
threading.
CO40585.5 5,12 H L H H M M
Student gains the
knowledge to
implement the
concept JDBC.
10
6 H M H L M
CO40585.6:
Student gains the
knowledge about
check box group
(radio button).
CO40585.7: 7 L M HL M M M
Student gains the
knowledge to
create an abstract
class and abstract
methods in swings
CO40585.8. 8 MH M H H H
. Student gains the
knowledge
About grid
layout to
display
tables of
data.
To view of
your data
by using
grid
layout.
CO40585.9: 9 M H M M
Student gains the
knowledge how to
invoke when the
mouse button has
been pressed,
clicked, entered,
exited and released
on the source
component.
11
CO40585.10: 10 MH M H H H
Student gains the
knowledge how to
organize the data
using hash table.
CO40585.11 11,12 MH M H H H
Student gains the
knowledge about
queries.
CO40585.12 12 MH M H H H
Student gains the
knowledge how to
access data from
file and database.
CO40585.13 13 MH M H H H
Student gains the
knowledge how to
prints the meta-
data of a given a
table.
12
WEEK 1
AIM:
Write a java program that works as a simple calculator. Use a grid layout to arrange
buttons for the digits and for the +, -, *, % operations. Add a text field to display the result.
Handle any possible exceptions like divided by zero.
PROGRAM:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Calculator extends Applet
implements ActionListener
{
String msg=" ";
int p,q,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init()
{
t1=new TextField(10);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{
b[i]=new Button(""+i);
}
add=new Button("add");
sub=new Button("sub");
mul=new Button("mul");
div=new Button("div");
mod=new Button("mod");
clear=new Button("clear");
EQ=new Button("EQ");
t1.addActionListener(this);
add(t1);
for(int i=0;i<10;i++)
{
add(b[i]);
}
add(add);
add(sub);
add(mul);
13
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}
14
t1.setText("");
}
else if(str.equals("mod"))
{
p=Integer.parseInt(t1.getText());
OP='%';
t1.setText("");
}
if(str.equals("EQ"))
{
q=Integer.parseInt(t1.getText());
if(OP=='+')
result=p+q;
else if(OP=='-')
result=p-q;
else if(OP=='*')
result=p*q;
else if(OP=='/')
result=p/q;
else if(OP=='%')
result=p%q;
t1.setText(""+result);
}
if(str.equals("clear"))
{
t1.setText("");
}
}
}
15
OUTPUT:
Viva Questions
16
WEEK 2
AIM:
PROGRAM:
import java.applet.Applet;
import java.awt.Graphics;
public class Hello extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello world",50,30);
}
}
OUTPUT:
17
b)Develop an applet that receives an integer in one text field, and computes its factorial
Value and returns it in another text field, when the button named “Compute” is clicked.
PROGRAM:
import java.awt.*;
import java.awt.event.*;
public class factorial extends java.applet.Applet implements ActionListener
{
TextField t1,t2;
Label l1,l2,l3;
Button b1;
int fact=1,n,i;
factorial e;
public void init()
{
e=this;
t1=new TextField(10);
t2=new TextField(10);
l1=new Label("factorial of a number");
l2=new Label("enter number");
l3=new Label("result");
b1=new Button("compute");
add(l1);add(l2);add(l3);add(t1);add(t2);add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=t1.getText();
n=Integer.parseInt(str);
for(i=n;i>1;i--)
{
fact=fact*i;
}
String msg=""+fact;
t2.setText(msg);
fact=1;
}
}
18
OUTPUT:
Viva Questions
1) What is an applet?
2) What are the different types of applets available in java?
3) Why it is not possible to use remote applet than local applet?
4) What are the different ways of creating a button, label, text field?
5) What is the use of Graphics Class?
19
WEEK3
AIM:
Write a program that creates a user interface to perform integer divisions. The user enters
two numbers in the textfields, Num1 and Num2. The division of Num1 and Num2 is
displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were not
an integer, the program would throw a NumberFormatException. If Num2 were Zero, the
program would throw an ArithmeticException Display the exception in a message dialog
box.
PROGRAM:
import java.awt.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.event.*;
public class Division extends Applet implements ActionListener{
TextField t1,t2,t3;
Button b;
Label L1,L2,L3,L4;
String s;
Division e;
public void init()
{
e=this;
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
L1=new Label("enter num1");
L2=new Label("enter num2");
L3=new Label("Result is");
L4=new Label("Division of 2 numbers");
b=new Button("Divide");
add(L4);
add(L1);
add(t1);
add(L2);
add(t2);
add(L3);
add(t3);
add(b);
20
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
int num1=Integer.parseInt(t1.getText());
int num2=Integer.parseInt(t2.getText());
s=""+(num1/num2);
t3.setText(s);
}
catch(ArithmeticException a)
{
JOptionPane.showMessageDialog(null,"Divide by zero");
}
catch(NumberFormatException b)
{
JOptionPane.showMessageDialog(null,"NumberFormateException");
}
}
}
OUTPUT:
Viva Questions
1) What is an exception?
2) What is the super class of all exception classes?
3) When does an number format exception occurs?
4) What are the different exceptions available in java programming language?
5) What is the difference between Interface and a class?
21
WEEK4
AIM:
Write a java program that implements a multi-thread applications that has three threads.
First thread generates random integer every 1 second and if the value is even, second
thread computes the square of the number and prints. If the value is odd, the thread will
print the value of the number.
PROGRAM:
package Mthread;
import java.util.Random;
public class Mthread {
public static void main(String args[])
{
A a=new A("one");
a.start();
}
}
class A extends Thread
{
String tname;
Random r;
Thread t1,t2;
A(String x)
{
this.tname=x;
}
public void run()
{
try
{
int num=0;
r=new Random();
num=r.nextInt(100);
for(int i=0;i<10;i++)
{
if(num%2==0)
{
t1=new Thread(new even(num));
t1.start();
22
}
else
{
t2=new Thread(new odd(num));
t2.start();
}
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Exception is"+e);
}
Catch(Exception a)
{
System.out.println("Exception is"+a);
}}}
class even implements Runnable
{
int x;
even(int x)
{
This.x=x;
}
public void run()
{
System.out.println(“num is even”+x+”its square is”+(x*x));
}}
class odd implements Runnable
{
int x;
odd(int x)
{
this.x=x;
}
public void run()
{
System.out.println(“num is odd”+x+”its cube is”+(x*x*x));
}
}
23
OUTPUT:
Viva Questions
1) What is a Thread ?
2) What are the different ways of using threads?
3) What is the difference between Runnable and Thread?
4) Explain the life cycle of a thread?
5) What is the difference between Stop and Wait?
24
WEEK5
AIM:
Write a java program that connects to a database using JDBC and does add, delete, modify
and retrieve operations.
PROGRAM:
import java.sql.*;
public class JdbcExample
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost/jdbc";
static final String USER="root";
static final String PASS="Gcet@05";
public static void main(String args[])
{
Connection conn=null;
Statement stmt=null;
try
{
System.out.println("connecting to database--");
conn=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("creating statement--");
stmt=conn.createStatement();
String sql,sql1,sql2,sql3;
Sql1=”insert into employee values(23,’bob’,’s’,20)”;
int s1= stmt.executeUpdate(sql1);
sql2=”update employee set age=18 where id=3”;
int s2= stmt.executeUpdate(sql2);
sql3=”delete from employee where id=24”;
int s3= stmt.executeUpdate(sql3);
sql="SELECT id,first,last,age FROM employee";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
int id=rs.getInt("id");
int age=rs.getInt("age");
String first=rs.getString("first");
String last=rs.getString("last");
System.out.println("ID:"+id);
System.out.println("Age:"+age);
System.out.println("First:"+first);
System.out.println("Last:"+last);
25
}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
System.out.println("Goodbye");
}
}
MYSQL:
OUTPUT:
connecting to database—
creating statement—
id:2 first:siri last:m age:23
id:3 first:deep last:v age:18
id:23 first:bob last:s age:20
Goodbye
Viva Questions
1) What is a database? Why do we need our program to communicate with the database?
2) Explain the concept of Jdbc?
3) What are the different types of driver available in java?
4) What is the use of Prepared Statement and a Statement object?
5) What is the use of Database Url ?
26
WEEK6
AIM:
Write a java program that simulates a traffic light. The program lets user select one of the
three lights: red, yellow, or, green with radio buttons. On selecting a button, an
appropriate message with “stop” initially, there is no message shown.
PROGRAM:
import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class Trafficlights extends Applet implements ItemListener{
String msg="";
Checkbox red,yellow,green;
CheckboxGroup cg=null;
public void init()
{
cg=new CheckboxGroup();
Checkbox red=new Checkbox("red",cg,true);
red.setBackground(Color.red);
Checkbox yellow=new Checkbox("yellow",cg,false);
yellow.setBackground(Color.yellow);
Checkbox green=new Checkbox("green",cg,false);
green.setBackground(Color.green);
add(red);
add(yellow);
add(green);
red.addItemListener(this);
yellow.addItemListener(this);
green.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
27
{
Checkbox chk=cg.getSelectedCheckbox();
g.drawString(chk.getLabel()+" Is selected",101,70);
}
}
OUTPUT:
Viva Questions
1) What is an applet ?
2) What is the difference between an application and an applet?
3) How do you run an applet application?
4) How do use threads in an applet?
5) What is an life cycle of an applet ?
28
WEEK7
AIM:
Write a java program to create an abstract class named shape that contains two integers
and an empty method named printArea(). Provide three classes named Rectangle, Triangle
and Circle such that classes contains only the method printArea() that prints the area of
the given shape.
PROGRAM:
import java.util.*;
abstract class shape
{
int x,y;
abstract void area(double x,double y);
}
class Rectangle extends shape
{
void area(double x,double y)
{
System.out.println("area of rectangle:"+(x*y));
}
}
class Circle extends shape
{
void area(double x,double y)
{
System.out.println("area of circle:"+(3.14*x*x));
}
}
class Triangle extends shape
{
void area(double x,double y)
{
System.out.println("area of triangle:"+(0.5*x*y));
}
}
public class AbstactDDemo
{
public static void main(String[] args)
{
Rectangle r=new Rectangle();
r.area(2,5);
Circle c=new Circle();
c.area(5,5);
Triangle t=new Triangle();
29
t.area(2,5);
}
}
OUTPUT:
area of rectangle:10.0
area of circle:78.5
area of triangle:5.0
Viva Questions
30
WEEK8
AIM:
Suppose that a table named Table.txt is stored in a text file. The first line in the file is the
header, and the remaining lines correspond to rows in the table. The elements are
separated by commas. Write a java program to display the table using Labels in Grid
Layout.
PROGRAM:
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
class A extends JFrame {
public A() {
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout g = new GridLayout(0,3);
setLayout(g);
try {
FileInputStream fin = new FileInputStream("D:/emp.txt");
Scanner sc = new Scanner(fin).useDelimiter(",");
String[] arrayList;
String a;
while (sc.hasNextLine()) {
a = sc.nextLine();
arrayList = a.split(",");
for (String i : arrayList) {
add(new
JLabel(i));
}
}
} catch (Exception ex) {
}
setDefaultLookAndFeelDecorated(true);
pack();
setVisible(true);
}
}
public class Tbl {
public static void main(String[] args) {
A a = new A();
}
}
31
OUTPUT:
Viva Questions
32
WEEK9
AIM:
Write a java program that handles all mouse events and shows the event name at the center
of the window when a mouse event is fired (use Adapter classes).
PROGRAM:
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JApplet;
33
}
public void mouseReleased(MouseEvent e)
{
x=e.getX();
y=e.getY();
event="Reeleased";
repaint();
}
public void mouseExited(MouseEvent e)
{
x=e.getX();
y=e.getY();
event="Exited";
repaint();
}
public void mouseEntered(MouseEvent e)
{
x=e.getX();
y=e.getY();
event="Entered";
repaint();
}
}
OUTPUT:
34
Viva Questions
35
WEEK10
AIM:
Write a java Program that loads names and phone numbers from a text file where the data
is organized as one line per record and each filed in a record are separated by a tab (\t). It
takes a name or phone number as input and prints the corresponding other value from the
hash table (hint: use hash tables).
PROGRAM:
import java.io.*;
import java.util.*;
public class Phonebook
{
public static void main(String args[])
{
Try
{
FileInputStream fis=new FileInputStream("//home/gcet/Desktop/myfile.txt");
Scanner sc=new Scanner(fis).useDelimiter("\t");
Hashtable<String,String> ht=new Hashtable<String,String> ();
String[] strarray;
String a,str;
while(sc.hasNext())
{
a=sc.nextLine();
strarray=a.split("\t");
ht.put(strarray[0],strarray[1]);
System.out.println("hash table values are"+strarray[0]+":"+strarray[1]);
}
Scanner s=new Scanner(System.in);
System.out.println("enter the name as given in the phone book");
str=s.next();
if(ht.containsKey(str))
{
System.out.println("phone no is"+ht.get(str));
}
else
{
System.out.println("name is not matched");
}
}
catch(Exception e)
{
System.out.println(e);
}}}
36
Myfile.txt
Surya 1234567
Ravi 456789
Sudha 6789900
OUTPUT:
Surya:1234567
Ravi:456789
Sudha:6789900
enter the name as given in the phone book
Ravi
phone no is: 456789
enter the name as given in the phone book
soni
name is not matched
Viva Questions
37
WEEK11
AIM:
Write a java Program that loads names and phone numbers from a text file where the data
is organized as one line per record and each filed in a record are separated by a tab (\t). It
takes a name or phone number as input and prints the corresponding other value from the
hash table with database instead of a text file.
PROGRAM:
import java.sql.*;
public class JdbcExample
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost/jdbc";
static final String USER="root";
static final String PASS="Gcet@05";
public static void main(String args[])
{
Connection conn=null;
Statement stmt=null;
try
{
System.out.println("connecting to database--");
conn=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("creating statement--");
stmt=conn.createStatement();
String sql;
System.out.println(“Enter the name as in database”);
String nm=sc.next();
sql="SELECT phone FROM phonenub where name="+nm;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
int phone=rs.getInt("phone");
System.out.println("phone:"+phone);
}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException se)
{
se.printStackTrace();}}
38
OUTPUT :
connecting to database—
creating statement—
Enter the name as in database
“surya”
Phone: 1234567
Viva Questions
39
WEEK12
AIM:
Write a java Program that takes tab separated data (one record per line) from a text file
and inserts them into a database.
PROGRAM:
import java.sql.*;
import java.io.*;
import java.util.*;
public class Tbltodb {
public static void main(String[] args) {
Connection cn;
Statement st;
try
{
cn=DriverManager.getConnection("jdbc:mysql://localhost/jdbc","root","Gcet@05");
st=cn.createStatement();
String sql="";
FileInputStream fin=new FileInputStream("D:\\myfile.txt");
Scanner sc=new Scanner(fin);
String[] arrayList;
String a="";
int i=0;
while(sc.hasNext())
{
a=sc.nextLine();
arrayList =a.split("\\s+");
sql="insert into emp values("+"'"+arrayList[0]+"','"+arrayList[1]+"')";
st.execute(sql);
i++;
System.out.println(arrayList[0]+":"+arrayList[1]);
}
System.out.println(i+" Records are inserted");
st.close();
cn.close();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
40
}
Myfile.txt
Surya 1234567
Ravi 456789
Sudha 6789900
MYSQL
OUTPUT:
Surya:1234567
Ravi:456789
Sudha:6789900
Viva Questions
41
WEEK13
AIM:
PROGRAM:
import java.sql.*;
import java.util.*;
public class Tblmdata {
public static void main(String[] args) {
Connection cn;
Statement st;
ResultSet rs, rs1;
ResultSetMetaData rsmd;
try {
Scanner sc = new Scanner(System.in);
System.out.println("------connecting database-----");
System.out.println("Enter Database Name");
String dbname = sc.next();
System.out.println("Enter Password");
String pass = sc.next();
42
}
rs.close();
cn.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}}
OUTPUT:
------connecting database-----
Enter Database Name
Jdbc
Enter Password
Gcet@05
-----------Database is jdbc
-------------------------
Tables are
-------------------------
-------Table Name: emp---------
Columns are
Column Name Column Type Size
----------------------------------
Id Int 30
Name varchar 20
Viva Questions
43
ADDITIONAL PROGRAMS
44
AIM
PROGRAM:
import java.io.*;
class Reverse
int n=579;
int rev=0,digit;
while(n>0)
digit=n%10;
rev=(rev*10)+digit;
n=n/10;
Output
The reverse of number is 9
45
AIM
Design and Develop a java program to find whether the given number is
Armstrong or not.
PROGRAM:
import java.io.*;
int k=Integer.parseInt(as[0]);
int n=k,d=0,s=0;
while(n>0)
d=n%10;
s=s+(d*d*d);
n=n/10;
if(k==s)
System.out.println("Armstrong number”);
else
System.out.println("Armstrong number”);
} }
Output
153
Armstrong number
46
AIM
Design and Develop a java program to read different inputs in a single line
and print in separate lines.
Program:
import java.util.*;
import java.io.*;
class Diff
String str=br.readLine();
String s1=st.nextToken();
String s2=st.nextToken();
String s3=st.nextToken();
String name=s1;
Int age=Integer.parseInt(s2);
float sal=float.parseFloat(s3);
}}
47
Output
enter emp name,age,sal
sneha,19,7000
emp age is 19
48
AIM
Design and Develop a java program to read marks of a student and print the
total and average of marks using scanner class.
PROGRAM:
import java.util.*;
import java.io.*;
class Student
float total=0,avg;
marks[i]=sc.nextInt();
for(int i=0;i<5;i++)
total+=marks[i];
avg=total/5;
49
}
OUTPUT
Enter marks
55
Enter marks
66
Enter marks
77
Enter marks
88
Enter marks
99
total is 385.0
avg is 77.0
50
AIM
PROGRAM:
import java.io.*;
Class TryDemo
int a,d,b=10;
try
a=0;
d=b/a;
catch (ArithmeticException e)
System.out.println (“ArithmeticException”);
OUTPUT
Arithmetic Exception THIS IS AFTER CATCH BLOCK
51