Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

I have a code below. The question is what happens if the try/catch block is missing?

I have a code below. The question is what happens if the try/catch block is missing?

Also, could you explain the role of the variable stop?

ExceptionPropagation.java:

public class ExceptionPropagation {

public static void main(String[] args) {

ExceptionTest ext = new ExceptionTest();

ext.test();

}

}

ExceptionTest.java:

import java.util.InputMismatchException;

import java.util.Scanner;

public class ExceptionTest {

public void test(){

double num1;

double num2;

double sum;

boolean stop = false;

do{

try{

Scanner scan = new Scanner(System.in);

System.out.println(“Purpose: The program will add two numbers that you enter”);

System.out.print(“Enter the first number: “);

num1 = scan.nextDouble();

System.out.print(“Enter the second number: “);

num2 = scan.nextDouble();

sum = num1 + num2;

System.out.println(“The sum of ” + num1 + ” and ” + num2 + ” equals ” + sum + “.\n”);

stop = true;

}catch(InputMismatchException e){

System.out.println(“\nMake sure you enter a number!\nTry again!\n”);

}

}

while (!stop);

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"