Exercice Java corrigé les outils de base du langage JAVA

public class Insertion {
            public static void main(String[] args) {
                                               Scanner sc=new Scanner(System.in);
                                               int t[] = new int[10],pos,x;
                                               for(int i=0;i<10;i++)
                                               t[i]= (int) (11*Math.random()+11);
                                                 for(int i=0;i<10;i++)
                                               System.out.print(" "+t[i]+" ");
                                               System.out.print("\nEntrez l’élement à inserer : ") ;
                                         x=sc.nextInt() ;   
                                         System.out.print("\nEntrez sa position: ") ;
                                         pos=sc.nextInt();
                                        if(pos<0 || pos>10)
                                        System.out.print("\nla position donnée est hors tableau! ");
                                        else {
                                       for(int i=10;i>pos+1;i--)
                                          t[i]=t[i-1];
                                          t[pos]=x; }
                                        for(int i=0;i<11;i++)
                                                System.out.print(" "+t[i]+" ");}}

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *