import java.io.*;

class Basicopdemo

{

public static void main(String as[])

{

double a,b;

DataInputStream dis;

try

{

dis=new DataInputStream(System.in);

do

{

System.out.println("enter first value a:");

String str1=dis.readLine();

a=Double.parseDouble(str1);

System.out.println("enter second value b:");

String str2=dis.readLine();

b=Double.parseDouble(str2);

if(a>0.0)

{

double add=a+b;

double sub=a-b;

double mul=a*b;

double div=a/b;

System.out.println("add=:"+add);

System.out.println("sub=:"+sub);

System.out.println("mul=:"+mul);

System.out.println("div=:"+div);

break;

}

System.out.println("given number is negative so try again:");

}

while(a<0.0);

}

catch(NumberFormatException e1)

{

System.out.println("invalid number");

}

catch(Exception e2)

{

System.out.println("error");

}

}

}


1. Output 

E:\sycs_22_23\java>java Basicopdemo

enter first value a:

15

enter second value b:

2.5

add=:17.5

sub=:12.5

mul=:37.5

div=:6.0


 2. Output:

E:\sycs_22_23\java>java Basicopdemo

enter first value a:

125

enter second value b:

2v

invalid number

E:\sycs_22_23\java>

E:\sycs_22_23\java>java Basicopdemo

enter first value a:

-40

enter second value b:

5

given number is negative so try again:

enter first value a:

100

enter second value b:

-4

add=:96.0

sub=:104.0

mul=:-400.0

div=:-25.0