From 22f306573d5b4a86b90bc8d3f3436faa44da04aa Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Mon, 14 Oct 2024 02:40:35 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week10" --- OOP/Java/Lab/Week10/Array_Exception.java | 39 ++++++++++++++ OOP/Java/Lab/Week10/EvenNumberHandling.java | 23 +++++++++ OOP/Java/Lab/Week10/Handled.java | 26 ++++++++++ .../Lab/Week10/MarkOutOfBoundsHandling.java | 51 +++++++++++++++++++ OOP/Java/Lab/Week10/negativearr.java | 21 ++++++++ 5 files changed, 160 insertions(+) create mode 100644 OOP/Java/Lab/Week10/Array_Exception.java create mode 100644 OOP/Java/Lab/Week10/EvenNumberHandling.java create mode 100644 OOP/Java/Lab/Week10/Handled.java create mode 100644 OOP/Java/Lab/Week10/MarkOutOfBoundsHandling.java create mode 100644 OOP/Java/Lab/Week10/negativearr.java diff --git a/OOP/Java/Lab/Week10/Array_Exception.java b/OOP/Java/Lab/Week10/Array_Exception.java new file mode 100644 index 0000000..ebb803f --- /dev/null +++ b/OOP/Java/Lab/Week10/Array_Exception.java @@ -0,0 +1,39 @@ +import java.util.*; +class ArrayOverflowException extends Exception +{ + int a; + ArrayOverflowException(int b) + { + a=b; + } + public String toString() + { + return "ArrayOverflowException:"+a+" is out of bound"; + } + +} +public class Array_Exception { + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int arr[]=new int[10]; + for(int k=0;k 100) { + throw new arkOutOfBoundsHandling("Marks should be between 0 and 100"); + } + } + Students student = new Students(studentName, studentMarks); + System.out.println("Students details: " + student.name); + System.out.print("Marks: "); + for (int mark : student.marks) { + System.out.print(mark + " "); + } + } catch (arkOutOfBoundsHandling e) { + System.out.println("Error: " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/OOP/Java/Lab/Week10/negativearr.java b/OOP/Java/Lab/Week10/negativearr.java new file mode 100644 index 0000000..ee7c43d --- /dev/null +++ b/OOP/Java/Lab/Week10/negativearr.java @@ -0,0 +1,21 @@ + +import java.util.Scanner; + +public class negativearr { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int n; + System.out.println("Enter the number of elements"); + n = sc.nextInt(); + try{ + int array[] = new int[n]; + System.out.println("Enter the elments"); + for (int i = 0; i < n; i++) { + array[i] = sc.nextInt(); + } + }catch(NegativeArraySizeException e){ + System.out.println("Error:"+e.toString()); + } + } +}