Corrigé de l’exercice 1 du TD4 (2014)

import java.util.Scanner;
public class AfficheNiemeTerme {
   public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
      System.out.print("Suite 1,2,4,7, ... Quel rang ? ");
      int n=s.nextInt();
      int cpt=1;
      int terme=1;
      int increment=1;
      while(cpt<n) {
         terme=terme+increment;
         increment++;
         cpt++;
      }
      System.out.println(terme);
   }
}