//DebugTwelve1; Chapter 12; Java Programming; Joyce Farrell; 8th Ed //error to b
ID: 3675936 • Letter: #
Question
//DebugTwelve1; Chapter 12; Java Programming; Joyce Farrell; 8th Ed
//error to be fixed
1 // This class determines the logarithm of a number
2 public class DebugTwelve1
3 {
4 public static void main(String[] args) throws ArithmeticException
5 {
6 double num = -8.8, result;
7 try
8 {
9 if(num <= 0)
10 throw(new ArithmeticException());
11 result = Math.log(num);
12 System.out.println("Result is " + result);
13 }
14 catch(ArithmeticException error)
15 {
16 System.out.println("Can't take logarithm for value of zero or lower");
17 }
18 }
19 }
Explanation / Answer
public class DebugTwelve1
{
public static void main(String[] args) throws ArithmeticException
{
double num = -8.8, result;
try
{
if(num <= 0)
throw(new ArithmeticException());
result = Math.log(num);
System.out.println("Result is " + result);
}
catch(ArithmeticException error)
{
System.out.println("Can't take logarithm for value of zero or lower");
}
}
}
debug:
Can't take logarithm for value of zero or lower
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.