Kelvineger

Algor2

Sep 4th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. //Faça um algoritmo que imprima a seguinte sequência: 8,10,16,18,32,34... p/ 20 termos
  2.  
  3. public class HelloWorld{
  4.  
  5.      public static void main(String []args){
  6.         int cont = 0;
  7.         int resultado = 8;
  8.        
  9.         public static int soma(int cont, int resultado){
  10.             if((cont % 2) == 0){
  11.                 return 2;
  12.             }else{
  13.                 return resultado * 2;
  14.             }
  15.         }
  16.        
  17.         while(cont <= 20){
  18.             cont++;
  19.             resultado = resultado + soma(cont, resultado);
  20.             System.out.println(resultado + ", ");
  21.         }
  22.      }
  23. }
Add Comment
Please, Sign In to add comment