Hi,
Im working on java program for make a simple converter from celcius to reamur and fahrenheit i want to make an exception handle if user try to insert celcius = 0 and >100 using try & catch feature in Java, but until now i couldnt make it, here is my current simple program
import java.util.Scanner;
public class temperatur2 {
public static void main( String [] args ){
short loop = 2;
while (loop == 2 ){
System.out.print( "\n 1. Convert Celcius to Reamur \n 2. Convert Celcius to Fahrenheit " );
System.out.print( "\n Insert your choice : " );
Scanner input = new Scanner(System.in);
short choose = input.nextShort();
if (choose == 1){
System.out.print( "\nInsert celcius degree: " );
int c = input.nextInt();
double r = c * 0.8;
System.out.println( c + " Degree Celcius equivalent to " + r + " reamur.\n");
loop = 1;
}
else if (pil == 2){
System.out.print( "\nInsert celcius degree:");
int c = input.nextInt();
double f = (9.0/5.0)*c+32;
System.out.print( c + " Degree Celcius equivalent to " + f + " Fahrenheit." );
loop = 1;
} else
{
System.out.println( "Sorry there is only two option 1 or 2\n") ;
loop = 2;
}
}
}
}
is there any idea how i implement exception in this program? any help and solution would be very appreciated