Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
37 views
5 pages
Lab Programs 9&10
Java program
Uploaded by
Madhu
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Lab programs 9&10 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
37 views
5 pages
Lab Programs 9&10
Java program
Uploaded by
Madhu
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Lab programs 9&10 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Lab programs 9&10 For Later
You are on page 1
/ 5
Search
Fullscreen
Lab Progran_9 Develop a JAVA program to raise a custom exception (user defined exception) for DivisionByZero using try, catch, throw and finally. AIN: To develop a JAVA program to raise a custom exception (user defined exception) for DivisionByZero using try, catch, throw and finally. import java.util. Scanner; class DivisionByZeroException extends Exception ‘ public DivisionByZeroException(String message) : super(message); » public class CustomExceptionWithUserInput ‘ public static void main(String{] args) t try { int numerator, denominator; Scanner scanner = new Scanner(System.in); // Input from the user System.out.print("Enter the numerator: "); numerator = scanner.nextInt(); System.out. print("Enter the denominator: denominator = scanner.nextInt(); scanner. close(); if (denominator 5 0) ‘throw new DivisionByZeroException("Division by zero is not allowed.") + int result = numerator / denominatoi System.out.println("Result of division: + result);catch (DivisionByZeroException e) < System.err.printn("Custom Exception Caught: e-getMessage()); : catch (ArithmeticException e) Systemerr.printIn("Arithmetic Exception Caught: e-getMessage(}); finally { System. out. printIn("Finally block executed." , } output: Enter the numerator: 10 Enter the denominator: 2 Result of division: 5 Finally block executed. Enter the numerator: 20 Enter the denominator: 0 Finally block executed. Custom Exception Caught: Division by zero is not allowed. RESULT: Thus, the program to develop a JAVA program to raise a custom exception (user defined exception) for DivisionByZero using try, catch, throw and finally has been executed successfully and the output was verified.Lab Program 10 Develop a JAVA program to create a package naned mypack and import & implement it in a suitable class. AIM: To develop a JAVA program to create a package named mypack and import & implement it in a suitable class. To create a Java package named mypack and import it in a suitable class, you can follow these steps in Eclipse: 1, Open Eclipse and create @ new Java project: © Go to File > New > Java Project. © Enter the project name, e.g., "MyPackageDemo," and click Finish, 2. Create a package named mypack: © Right-click on the "src" folder within your project. o Choose New > Package. © Enter "mypack" as the package name and click Finish. 3. Create a class within the mypack package: e Right-click on the mypack package. © Choose New > Class. © Enter a class name, e.g., “Circle” and select the option to include the public static void main(String[] args) method. © Click Finish, 4.Now, you can implement the code to calculate the area of a circle in the Circle class: mypack/Circle,java Package mypack; // Inport the mypack package import java.util.Scanner; public class Circle { public static void main(Stringl] args) {Scanner scanner = new Scanner(System..in); System.out.print("Enter the radius of the circle: " double radius = scannersnextDouble(); double area = calculateCircleArea(radius); Systen.out.println("The area of the circle is: " + area); scanner. close(); + public static double calculateCircleArea(double radius) { return Math.PI * radius * radius; + } To use the mypack package in another class and calculate the area of a circle using the import statement, you can follow these steps: 1. Create a new Java class in your project. Let's call it MainClass in a different package (e.g., myapp). 2, Import the mypack package in your MainClass and use it to calculate the area of a circle. 3. To run the program, right-click on the MainClass and select "Run As" > "Java Application." nyapp/MainClass. java package myapp; // This is the package for MainClass import nypack.Circl // Inport the Circle class from mypack public class MainClass { public static void main(String{] args) { Circle circle = new Circle(); // Create an instance of the Cirele class double radius = 5.0; // You can set your own radius here double area = circle.calculateCircleArea(radius); // Use the method from the Circle class System.out.println("The area of the circle is: " + area);output: ‘The area of the circle is: 78.53981633974483, RESULT: Thus, the program to create a package named mypack and import & implement it in a suitable class has been executed successfully and the output was verified.
You might also like
OOPS With Java BCS306A Mod 4 Notes For Exam @vtunetwork
PDF
No ratings yet
OOPS With Java BCS306A Mod 4 Notes For Exam @vtunetwork
33 pages
Java Module5 Bplck205c
PDF
No ratings yet
Java Module5 Bplck205c
16 pages
JAVA Practical File
PDF
No ratings yet
JAVA Practical File
97 pages
BCS304-Module 3 Notes (Sowmya)
PDF
100% (1)
BCS304-Module 3 Notes (Sowmya)
6 pages
Aoop - Unit III
PDF
No ratings yet
Aoop - Unit III
108 pages
Unit 4
PDF
No ratings yet
Unit 4
49 pages
SDF III Chapter2
PDF
No ratings yet
SDF III Chapter2
32 pages
Chapter 3
PDF
No ratings yet
Chapter 3
79 pages
Cos 201 - Comp Programming Class Ii - 101042
PDF
No ratings yet
Cos 201 - Comp Programming Class Ii - 101042
44 pages
Chandan Final
PDF
No ratings yet
Chandan Final
19 pages
User Defined Exception: Compiled By: Aneeta Siddiqui
PDF
No ratings yet
User Defined Exception: Compiled By: Aneeta Siddiqui
17 pages
Module 4 Topic Wise 2024-25 End
PDF
No ratings yet
Module 4 Topic Wise 2024-25 End
44 pages
Oop2017 2
PDF
No ratings yet
Oop2017 2
60 pages
Java Package - 21 - 11 - 2023 - Lecture Note
PDF
No ratings yet
Java Package - 21 - 11 - 2023 - Lecture Note
91 pages
OOPJ (Java) Unit-IV
PDF
No ratings yet
OOPJ (Java) Unit-IV
47 pages
Java 3
PDF
No ratings yet
Java 3
64 pages
Packages
PDF
No ratings yet
Packages
22 pages
Java Package
PDF
No ratings yet
Java Package
68 pages
Module 4
PDF
No ratings yet
Module 4
27 pages
BE Java Module - 4
PDF
No ratings yet
BE Java Module - 4
54 pages
Java Tutorial Excelente Importante
PDF
No ratings yet
Java Tutorial Excelente Importante
211 pages
BCS306A-module 3,4,5 3rd Sem
PDF
No ratings yet
BCS306A-module 3,4,5 3rd Sem
24 pages
Experiment No.:-08: Experiment No.: 8 Date of Performanc E: Date of Submissio N
PDF
No ratings yet
Experiment No.:-08: Experiment No.: 8 Date of Performanc E: Date of Submissio N
4 pages
Java Programming Notes4
PDF
No ratings yet
Java Programming Notes4
11 pages
Java Module 4
PDF
No ratings yet
Java Module 4
37 pages
2 Overview Ofjava Programming
PDF
No ratings yet
2 Overview Ofjava Programming
78 pages
9e Packages
PDF
No ratings yet
9e Packages
17 pages
Operating System
PDF
No ratings yet
Operating System
25 pages
Library Classes and Packages
PDF
No ratings yet
Library Classes and Packages
28 pages
Packages Applet
PDF
No ratings yet
Packages Applet
15 pages
Unit 2 Second Half
PDF
No ratings yet
Unit 2 Second Half
14 pages
2 PDF
PDF
No ratings yet
2 PDF
46 pages
CH7 Programs
PDF
No ratings yet
CH7 Programs
10 pages
Unit 4
PDF
No ratings yet
Unit 4
10 pages
Java File Hritik
PDF
No ratings yet
Java File Hritik
35 pages
Clean Water and Sanitation
PDF
No ratings yet
Clean Water and Sanitation
13 pages
Mrs. Rojalin Mallick Lecturer, CSA, CET
PDF
No ratings yet
Mrs. Rojalin Mallick Lecturer, CSA, CET
24 pages
Java
PDF
No ratings yet
Java
15 pages
Unit IV
PDF
No ratings yet
Unit IV
23 pages
Lecture 4
PDF
No ratings yet
Lecture 4
26 pages
Introduction To Java Programming
PDF
No ratings yet
Introduction To Java Programming
29 pages
Topic 6 - Math Class in Java
PDF
No ratings yet
Topic 6 - Math Class in Java
8 pages
Unit Iii
PDF
No ratings yet
Unit Iii
43 pages
Sample Java Programs
PDF
No ratings yet
Sample Java Programs
28 pages
Unit 4
PDF
No ratings yet
Unit 4
14 pages
PRG 10
PDF
No ratings yet
PRG 10
3 pages
Java - Programming Module3 (Packages & Exception Handling)
PDF
No ratings yet
Java - Programming Module3 (Packages & Exception Handling)
15 pages
Assignment 2
PDF
No ratings yet
Assignment 2
16 pages
IT 201 Module 2
PDF
No ratings yet
IT 201 Module 2
17 pages
Package&interface 9 B
PDF
No ratings yet
Package&interface 9 B
50 pages
Java
PDF
No ratings yet
Java
96 pages
MPL WK 7 Lec 13 14 Asg PDF
PDF
No ratings yet
MPL WK 7 Lec 13 14 Asg PDF
16 pages
Abstract Class Interface: Types of Packages: Built-In and User Defined
PDF
No ratings yet
Abstract Class Interface: Types of Packages: Built-In and User Defined
31 pages
Network Programming Section1
PDF
No ratings yet
Network Programming Section1
6 pages
Java Programming Laboratory Lab Manual
PDF
No ratings yet
Java Programming Laboratory Lab Manual
27 pages
Cs6501 - Internet Programming
PDF
No ratings yet
Cs6501 - Internet Programming
19 pages
OOP Templates Assignment - Zip
PDF
No ratings yet
OOP Templates Assignment - Zip
31 pages
Calculate Circle Area Using Java Example: Home Fundamentals Common Java - Lang File Io Collections Applets & Awt Misc Swing
PDF
No ratings yet
Calculate Circle Area Using Java Example: Home Fundamentals Common Java - Lang File Io Collections Applets & Awt Misc Swing
4 pages
Ada m5 Part 1 Notes - @vtupadhai
PDF
No ratings yet
Ada m5 Part 1 Notes - @vtupadhai
12 pages
Java Program To Calculate Area of Circle
PDF
No ratings yet
Java Program To Calculate Area of Circle
5 pages
New - Solveathon 2.0 Templete - 1
PDF
No ratings yet
New - Solveathon 2.0 Templete - 1
9 pages
Auv Paper
PDF
No ratings yet
Auv Paper
8 pages
Important Program in Java
PDF
No ratings yet
Important Program in Java
8 pages
How Do I Set or Change The PATH System Variable?
PDF
No ratings yet
How Do I Set or Change The PATH System Variable?
14 pages
Jarvis Presentation
PDF
No ratings yet
Jarvis Presentation
2 pages
Advaya CSE Magazine Article Ideas
PDF
No ratings yet
Advaya CSE Magazine Article Ideas
2 pages
DIGITAL Disgram
PDF
No ratings yet
DIGITAL Disgram
6 pages
m1 Maths
PDF
No ratings yet
m1 Maths
2 pages