-
-
Save marioluan/3982122 to your computer and use it in GitHub Desktop.
/* Construir um algoritmo para imprimir a série de FIBONACCI até o 10º termo. | |
* A série de FIBONACCI é formada pela sequência: | |
*0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55... | |
*/ | |
package cap14; | |
public class Exercicio02 { | |
public static void main(String[] args){ | |
int num1 = 1, num2 = 0; | |
System.out.println(num2); | |
System.out.println(num1); | |
for(int i = 0; i < 8; i++){ | |
num1 = num1 + num2; | |
num2 = num1 - num2; | |
System.out.println(num1); | |
} | |
} | |
} |
Very Good!
Thank you so much yeah
Eu gostaria de saber como faz para colocar a sequência na horizontal.
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package exercicio13;
/**
*
- @author marcio
*/
/* Imprima os 30 primeiros elementos da série de Fibonacci. A sé-
rie é a seguinte: 1, 1, 2, 3, 5, 8, 13, 21 etc. Para calculá-la, o primei-
ro e segundo elementos valem 1, daí por diante, cada elemento
vale a soma dos dois elementos anteriores (ex: 8 = 5 + 3).
*/
public class Exercicio13 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int n1 = 1;
int n2 = 0;
for (int i = 1; i <= 30; i++){
if (i < 2){
System.out.println(1);
} else {
n1 = n1 + n2;
n2 = n1 - n2;
System.out.println(n1);
}
}
}
}
/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic hereint n1 = 1;
int n2 = 0;for (int i = 1; i <= 30; i++){
if (i < 2){System.out.println(1);
} else {
n1 = n1 + n2;
n2 = n1 - n2;/* O comando System.out.println pula uma linha e o comando system.out.print mantem na mesma.
então se utilizar o comando print vai manter mas os valores vão estar colados e por isso você tem que
adicionar um espaço a caixa de texto ficando assim:
*/
System.out.print(n1 +" ");
}
}
}
}
Muito bom!