java 5
java 5
Aim 5(a): Write a Java program to implement user defined exception handling for negative
amount entered.
Code:
import java.util.*;
public NewException(float n)
try{
if(amt<0)
catch(NewException ex)
System.out.println("Exception");
Output:
5(b): Write a program in java which creates two threads, “Even” thread and “Odd” thread
and print the even no using Even Thread after every two seconds and odd no using Odd
Thread after every five second.
Code:
for(int i=1;i<10;i+=2)
try{
Thread.sleep(5000);
catch(InterruptedException e)
System.out.println(e);
for(int i=0;i<10;i+=2)
try{
Thread.sleep(5000);
catch(InterruptedException e)
{
System.out.println(e);
class thread{
obj1.start();
obj2.start();
Output: