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) {
- int n;
- double sum;
- boolean isNotCorrect;
- Scanner scan = new Scanner(System.in);
- sum = 0.0;
- System.out.println("Эта программа вычисляет сумму по формуле S от 1 до n 1/i^3");
- n = 0;
- do {
- System.out.println("Введите число n от 1 до 200");
- isNotCorrect = false;
- try
- {
- n = Integer.parseInt(scan.nextLine());
- }
- catch(NumberFormatException exception)
- {
- isNotCorrect = false;
- System.out.println("Пожалйста, вводите числа");
- }
- }
- while (isNotCorrect);
- for(int i = 1; i <= n; i++)
- {
- sum += 1.00/(i*i*i);
- }
- scan.close();
- System.out.println("Новая сумма равна: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment