Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.PrintStream;
- import java.util.Scanner;
- public class Problem3 {
- public static void main(String args[]) throws java.io.UnsupportedEncodingException {
- PrintStream ps = new PrintStream(System.out, true, "UTF-8");
- Scanner in = new Scanner(System.in);
- double eps, sum, k;
- boolean isNotCorrect;
- isNotCorrect = true;
- sum = 0;
- k = 1;
- eps = 0;
- ps.println("Введите EPS: ");
- do {
- try {
- eps = Double.parseDouble(in.nextLine());
- if ((eps > 1) || !(eps > 0))
- ps.println("Введите действительное число в диапазоне (0; 1]");
- else isNotCorrect = false;
- }
- catch (NumberFormatException err) {
- ps.println("Некорректный ввод данных!");
- }
- } while (isNotCorrect);
- while (!(k < eps)) {
- sum = sum + k;
- k = k / 2;
- }
- ps.print("Сумма членов ряда: ");
- ps.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement