Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class teste1 {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner s = new Scanner(System.in);
  7.         int valor, temp, b = 1, soma = 0;
  8.  
  9.         System.out.println("Digite o valor");
  10.         valor = s.nextInt();
  11.         System.out.print("{");
  12.         //o laço vai armazenar os 2 valores anteriores e soma-los numa terceira variavel "soma".
  13.         for (int i = 0; i < valor; i++) {
  14.             temp = soma;
  15.             soma += b;
  16.             b = temp;
  17.             //ignora, foi só pra deixar a exibicao em forma de conjunto: { valor1,valor2,valor3...valorN}
  18.             System.out.print(soma + ",");
  19.         }
  20.         System.out.println("}");
  21.  
  22.     }
  23.  
  24. }
Add Comment
Please, Sign In to add comment