Question: Java return values print statement I have made a program to calculate the root square newtonian approximation method and I should compare it with the

Java return values print statement I have made a program to calculate the root square newtonian approximation method and I should compare it with the library function which is included for calculating the sqrt. My problem is that my output is not working because I have to many arguments for the print statement (line 130-140). I know there is a issue with my return statements. I was checking all functions and I always have the right values in each method. Only in the print method it dissapears.

Java return values print statement I have made a program to calculate

the root square newtonian approximation method and I should compare it with

the library function which is included for calculating the sqrt. My problem

But the output should look like this : is that my output is not working because I have to many

Can someone help me for my print statment?

Code

import java.io.BufferedReader; import java.io.InputStreamReader;

public class Aufgabe04_2 { static double x = 0; static int iterations = 0; static double epsilon = 0; // loop method for calling all other methods. public static void main(String[] args) {

try { readFloat(); readIterations(); readEpsilon(); printResults(); sqrtNewtonIter(x, iterations); sqrtNewtonDelta(x, epsilon); libraryFunction(x);

} catch (Exception e) { System.out.println(e.getMessage()); } }

public static double readFloat() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("x= ");

while (true) { try {

String input = new String(); input = br.readLine(); x = Double.parseDouble(input);

} catch (Exception e) {

System.out.println("x= "); continue; } break; } return x; }

public static int readIterations() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Wie viele Iterationen sollen durchgefhrt werden? ");

while (true) { try {

String input = new String(); input = br.readLine(); iterations = Integer.parseInt(input);

} catch (Exception e) {

System.out.println("Wie viele Iterationen sollen durchgefhrt werden? "); continue; } break; } return iterations; } public static double readEpsilon() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Genauigkeit= ");

while (true) { try {

String input = new String(); input = br.readLine(); epsilon = Double.parseDouble(input);

} catch (Exception e) {

System.out.println("Genauigkeit= "); continue; } break; } return epsilon; } static double sqrtNewtonIter(double x, int iterations) {

double a0 = x / 2; double b0 = 2.0; double an = a0; double bn = b0;

for (int i = 0; i

return an; }

static double sqrtNewtonDelta(double x, double epsilon) {

double a0 = x / 2; double b0 = 2.0; double an = a0; double bn = b0; double difference = 0;

do { bn = (an + bn) / 2; an = x / bn; difference = Math.abs(an - bn); } while (difference > epsilon);

return an; } static double libraryFunction(double x) {

return Math.sqrt(x);

} static void printResults() { System.out.println(" Ergebnis (iterative Variante):"); System.out.format("%d Iterationen ", iterations); System.out.format("sqrt(%s) = %d ", x, sqrtNewtonIter(x, iterations));

System.out.println("Ergebnis (Delta-Variante):"); System.out.format("epsilon=%s ", epsilon); System.out.format("sqrt(%s) = %s ", x, sqrtNewtonDelta(x, epsilon)); System.out.println();

System.out.println("Ergebnis (Bibliotheksfunktion):"); System.out.format("Math.sqrt(%s) = %s ", x, libraryFunction(x)); } }

Console X kterminated> Aufgabe04 2 [Java Application] C:Program FilesJavaljre-10.0.2bin javaw x12345 Wie viele Iterationen sollen durchgefhrt werden? 010 Genauigkeit- 0.1 Ergebnis (iterative Variante): 10 Iterationen sqrt(12345.8) = d != iava.lang. Double

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!