cours_progra/q2/algo/tp1/Suite.java

33 lines
683 B
Java
Raw Normal View History

2023-03-09 11:38:23 +01:00
public class Suite {
public static void main(String[] args) {
// suiteArithmetique(5, 5, 3);
// suiteGeometrique(5, 5, 3);
suiteFibonacci(15);
}
public static void suiteArithmetique(int depart, int raison, int k){
for (int i = 0; i < k; i++) {
System.out.println(depart + raison * i);
}
}
public static void suiteGeometrique(int depart, int raison, int k){
for (int i = 0; i < k; i++) {
System.out.println(depart + (int)Math.pow(raison, i));
}
}
public static void suiteFibonacci(int k){
int el1 = 1;
int el2 = 1;
int temp;
for (int i = 0; i < k-2; i++) {
temp = el1;
el1 = el2;
el2 = temp + el2 ;
}
System.out.println(el2);
}
}