Java 28 - user defined using throw
Sun Nov 26 2023 17:12:43 GMT+0000 (Coordinated Universal Time)
Saved by
@Java
import java.util.*;
class B extends RuntimeException
{
B(String a)
{
super(a);
}
public static void main(String... args)
{
int balance=1700;
Scanner x=new Scanner(System.in);
System.out.print("Enter amount=");
int amount=x.nextInt();
if(amount>balance)
{
throw new B("Invalid balance");
}
else
{
System.out.println("Your Amount ="+amount);
}
}
}
content_copyCOPY
Comments