Skip to content

Commit

Permalink
array
Browse files Browse the repository at this point in the history
  • Loading branch information
arijit2002 authored Oct 1, 2023
1 parent 9eb43ed commit 1b598c4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions java/TestArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.Scanner;


class NegativeSizeException extends Exception {

NegativeSizeException(String message) {
super(message);
}

}

class TestArray {
public static void main(String args[]) throws NegativeSizeException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter array size");
int n = sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter array elements ");
for (int i = 0; i < n; i++) {
int r = sc.nextInt();
if (r < 0)
throw new NegativeSizeException("Negative values not excepted");
else
arr[i] = r;
}
sc.close();
}
}

0 comments on commit 1b598c4

Please sign in to comment.