Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class gseries
- {
- public static void main(String[] args)
- {
- Scanner kboard = new Scanner(System.in);
- System.out.print("Gregory series terms: ");
- int gregory = kboard.nextInt();
- double bottom = 3;
- double result = 4;
- for(int i = 0; i < gregory-1; i++) {
- if(i%2==0) {
- result -= (4/bottom);
- bottom += 2;
- } else {
- result += (4/bottom);
- bottom += 2;
- }
- }
- System.out.println("Answer: "+result);
- kboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement