Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int i = 0;
- double x =0, y, yi, eps = 0;
- boolean isCorrect;
- Scanner scan = new Scanner(System.in);
- System.out.println("Введите eps:");
- do
- {
- isCorrect = false;
- try {
- eps = Double.parseDouble(scan.nextLine());
- }
- catch(Exception e) {
- System.out.println("eps введено некорректно!!!\nВведите eps:");
- isCorrect = true;
- }
- if (!isCorrect && (eps <= 0 || eps >= 1)){
- System.out.println("Заданное число не может являться eps!!!\nВведите eps(число от нуля до единицы):");
- isCorrect = true;
- }
- } while (isCorrect);
- System.out.println("Введите x:");
- do
- {
- isCorrect = false;
- try {
- x = Double.parseDouble(scan.nextLine());
- }
- catch(Exception e) {
- System.out.println("x введён некорректно!!!\nВведите x:");
- isCorrect = true;
- }
- } while (isCorrect);
- scan.close();
- yi = 1;
- do
- {
- i++;
- y = yi;
- if (y != 0)
- yi =(2 * y + x / y / y) / 3;
- } while (Math.abs(y - yi) > eps);
- if (y == 0)
- System.out.println("Ошибка!!!\nВ ходе программы произошло деление на 0.\n");
- else
- System.out.println("Корень кубический из х = " + yi + "; Количество итераций : " + i + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement