Exercice 1 :


afficher un triangle d'étoiles, on lit le nombre le ligne au clavier et on affiche n lignes d'étoiles comme suite :

par exemple n=5 

*
**
***
****
*****
****
***
**
*


Correction :


public class Etoile {
     private static int n;
    public static void main(String args[]){
     
        System.out.println("Entrez le nombre de ligne:");
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        for(int i=0;i<n;i++){
               for(int j=0;j<i;j++)
                System.out.print("*");
       
        System.out.println();
          }
        for(int e=n;e>0;e--){
                    for(int j=0;j<e;j++)
                System.out.print("*");
                 
               System.out.println();
            }
            
        }
   
}


Commentaires