Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class gseries
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner kboard = new Scanner(System.in);
  8. System.out.print("Gregory series terms: ");
  9. int gregory = kboard.nextInt();
  10. double bottom = 3;
  11. double result = 4;
  12. for(int i = 0; i < gregory-1; i++) {
  13. if(i%2==0) {
  14. result -= (4/bottom);
  15. bottom += 2;
  16. } else {
  17. result += (4/bottom);
  18. bottom += 2;
  19. }
  20. }
  21. System.out.println("Answer: "+result);
  22. kboard.close();
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement