Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main3 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- final String error = "Ошибка ввода! Введите число большее 0, но меньшее 1";
- final String errorX = "Ошибка ввода! Введите число большее (от -1000000 до 1000000)";
- double x = 0.0;
- double eps = 0.0;
- boolean isCorrect = true;
- System.out.println("Введите точность вычислений eps (0<eps<1)");
- do {
- try {
- eps = in.nextDouble();
- if (eps > 0 && eps < 1) {
- isCorrect = false;
- }
- else {
- System.out.println(error);
- }
- }
- catch (Exception e) {
- System.out.println(error);
- in.nextLine();
- }
- }
- while (isCorrect);
- isCorrect = true;
- System.out.println("Введите число Х (от -1000000 до 1000000)");
- do {
- try {
- x = in.nextDouble();
- if (x > -1000001 && x < 1000001) {
- isCorrect = false;
- }
- else {
- System.out.println(errorX);
- }
- }
- catch (Exception e) {
- System.out.println(errorX);
- in.nextLine();
- }
- }
- while (isCorrect);
- double fun;
- double delta = 1.0;
- while (delta > eps) {
- fun = Math.tan(1.5773 * x) / 2.3041;
- delta = fun - x;
- x = fun;
- }
- System.out.printf("Корень уравнения равен %.5f", x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment