Question: Write a program that reads in two double numbers followed by an integer (say n). The goal of the program is to check if the

Write a program that reads in two double numbers followed by an integer (say n).

The goal of the program is to check if the two numbers are equal to n significant digits (See Sec 3.2 Common Error 3.2 on page 87 of textbook).

Input:

The input will be one or more lines of three numbers. The first two numbers are doubles and represent the two numbers that are to be compared. The third number is an integer and represents the number of significant digits to check (for equality of the two numbers).

Output:

The output will show the difference up to 10 decimal places (as shown in sample output) and then whether the numbers are equal or not.

Sample Input:

1.112 1.113 2

1.123 1.124 3

Sample Output:

difference = 0.0010000000 , Numbers are equal to 2 decimal places

difference = 0.0010000000 , Numbers are not equal to 3 decimal places

HINT

1. To print difference to 10 decimal places use System.out.printf("%.10f", diff);

2. Compare difference of numbers against 1.0 / Math.pow(10, n) where, n is the integer being read in by the program.

3. Make sure to take the absolute value of the difference when you compare. Use Math.abs method to get the absolute value.

I have written my code, however it is not passing my test cases. What do i need to change?

Write a program that reads in two double numbers followed by an

Real Equity/src/RealEquity java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help Quick Access| | || s Pa CountUpperCase java ManyNumbers,java RealEquity java 3 | 1 import java . util-Scanner; 3 public class RealEquity t Colc Calculator CountUpperCose public static void main(string] args) i RealEquity Elevator JRE System Lit 7 Scanner scanner new Scanner(System.in); main(Stri while (scanner.hasllext O) (defoult pa 0 Elevator11 Elevator12 String line scanner.nextline) String str[] line.split(""); double firstNum = Double.parseDouble(str(); double secondlum Double.parseDouble(str[l]); int nun = Integer.parseInt(str.[2]); long tempFirst " (long) (firstNum Math.pon(10, > LineCounter Real Equity > replace ThreeNumbers num)); 20 21 long tempSecond (long) secondNumath.pov(18, num)); if (tempFirsttempSecond) [ 23 24 system . out .printf("difference-%.10f", Math.abs(firstNum- secondNum)); System.out.println(" , Numbers are equal tonum "decimal places"); else if (tempFirst>- tempSecond)t system.out.printt("difference-%.10f., Math.abs(firstNum- secondNum)); System.out.println"Numbers are not equal to numdecinal places"); 28 8 31 32 , problems @lavadocDeclaration ion CProgram Fi Console X Coverage re1.8.0 1811bin exe (Oct 31, 2018,9:02:11 Smart Insert 30:8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!