This is a debugging question - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors,...


This is a debugging question -



The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.



Code I was given -




// A byte can't hold a value higher than 127

// This program throws an ArithmeticException

// if adding two bytes yields a value that is too high

public class DebugTwelve2

{

   public static void main(String[] args)

   {

      byte num1 = 120, num2 = 120, result;

      final byte HIGHBYTE = 127;

      try

      {

         allowed = (byte)(HIGHBYTE - num1);

         if(num2 > allowed)

            throw(new Arithmeticexception());

         result = (byte)(num1 + num2);

         System.out.println("Result is  + result);

      }

      catch(ArithmeticcException error)

      {

         System.out.println("Byte can't hold value higher than " + HIGHBYT);

      }

   }

}




Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here