Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double x0 = 0;
- double x1 = 0;
- double e = 1;
- boolean isIncorrect;
- String inputLine = "";
- do {
- isIncorrect = false;
- System.out.println("Введите необходимую точность");
- inputLine = scanner.nextLine();
- try {
- e = Double.parseDouble(inputLine);
- }
- catch (NumberFormatException ex) {
- System.err.println("Точность должна быть числом");
- isIncorrect = true;
- }
- if (e < 0 && !isIncorrect) {
- isIncorrect = true;
- System.err.println("Точность должна быть больше 0");
- }
- } while (isIncorrect);
- do {
- isIncorrect = false;
- System.out.println("Введите первое приближение");
- inputLine = scanner.nextLine();
- try {
- x1 = Double.parseDouble(inputLine);
- } catch (NumberFormatException ex) {
- System.err.println("Первое приближение должно быть числом");
- isIncorrect = true;
- }
- } while (isIncorrect);
- do {
- x0 = x1;
- x1 = 9.33 * Math.sin(6.977 * x0) / 7.25;
- } while (Math.abs(x0 - x1) > e);
- System.out.printf("Корень равен %10.4f", x1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement