Advertisement
joaopedrobc

Untitled

Nov 17th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public static void main(String[] args) {
  2.     Scanner scanner = new Scanner(System.in);
  3.     System.out.print("Digite o valor do termo: ");
  4.     int value = scanner.nextInt();
  5.        
  6.     double answer = 0;
  7.     for(int i = 2; i <= value; i++){
  8.         double topValue = i;
  9.         double bottomValue = (i-1) * (i-1);    
  10.         if(i % 2 == 0){
  11.             answer = answer + (topValue / bottomValue);
  12.         } else{
  13.             answer = answer - (topValue / bottomValue);
  14.         }
  15.     }
  16.        
  17.     System.out.println("O valor do termo é " + answer);
  18.     scanner.close();
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement