Так это для класса. Кажется, я не могу понять сложность длинного деления. Откровенно говоря, я даже не уверен, как начать решать алгоритм, чтобы сделать его то, что мне нужно. < /p>
Для этой второй части мы должны принять номер ввода пользователя и найти квадратный корень в определенное количество десятичных знаков, которые пользователь также вводит. Алгоритм, который мне нужно воспроизвести, чтобы найти квадратный корень, можно найти здесь.import java.util.*;
import java.math.*;
import TerminalIO.*;
public class squareRootProgram{
public static float squareRootDiv(String number, int decimals){
String[] test = new String[2];
float answer = 0;
String groups = "";
test = number.split("\\.");
test = number.split("\\.");
System.out.println(test[0]);
System.out.println(test[1]);
for(int i = 0; groups != test.toString(); i++){
test.length();
}
return answer;
}
public static void main(String[]args){
KeyboardReader reader = new KeyboardReader();
String response = " ";
String initNumber = " ";
float number = 0;
int decimals = 0;
System.out.println("Welcome to the square root program.");
do{
addLine();
System.out.print("Please enter the number of which you want to find the square root: ");
initNumber = reader.readLine();
number = Float.valueOf(initNumber);
System.out.println(number);
System.out.print("Please enter the number of decimal places in which you want your answer: ");
decimals = reader.readInt();
System.out.println("The answer provided by division algorithm is " + squareRootDiv(initNumber,decimals));
addLine();
System.out.print("Would you like to try another number?: ");
response = reader.readLine();
}while(response.compareTo("no")!=0);
}
}
< /code>
Пример необходимого вывода для этого: < /p>
Welcome to the square root program.
Please enter the number of which you want to find the square root: 3.14159
Please enter the number of decimal places in which you want your answer: 3
The answer provided by division algorithm is 1.772
Would you like to try another number?: no
Thank you for using my program.
< /code>
Очевидно, что это необходимо работать для любого числа ввода и любого количества десятичных знаков, которые пользователь хотел бы, чтобы квадратный корень вернулся.
Подробнее здесь: https://stackoverflow.com/questions/306 ... ion-method