Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Pgm 1 || Section B || Program to catch Negative Array Size Exception. This exception is caused when the array size is initialized to negative values.

 import java.util.Scanner;

public class Pgm1

{

public static void main(String[] args)

{

try

{

Scanner ins=new Scanner(System.in);

System.out.println("Enter the size of the Array");

int size=ins.nextInt();

int[] array = new int[size];

System.out.println("Array length: " + array.length);

}

catch (NegativeArraySizeException e)

{

System.out.println("Array Size is Negative.");

e.printStackTrace();

}

}

}

Post a Comment

0 Comments