MIT-Curricular/OOP/Java/Lab/Week10/negativearr.java

22 lines
616 B
Java
Raw Normal View History

2024-10-14 02:40:35 +05:30
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());
}
}
}