⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pile.java

📁 在Java中实现数字的加、减、乘、除等运算。
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package calculatrice;/** * * @author cgu */public class Pile {//attribut     /**     * indice du tableau tab     * par defaut initialisé à zéro     * pointe sur le prochain element a empiler      * <p>     */    public int sommet;    public int capacite;    public int[] tab;    //constructeur    /**     *      * @param taille     */    public Pile(int taille){        //initialisation des attributs et allocation        sommet=0;        capacite=taille;        tab=new int[capacite];     } //méthodes privées     //méthodes visibles    public int getcapacite(){        return capacite;    }        public int getsommet(){        return tab[sommet-1];    }        public void empiler(int valeur){        tab[sommet]=valeur;        sommet++;    }        public int depiler(){        sommet--;        return tab[sommet];    }       public boolean estvide(){        return sommet==0;    }        public boolean estpleine(){        return sommet==capacite;    }        public void afficherTab(){         int i=0;        System.out.println("tableau :");        for(i=0;i<capacite;i++){            System.out.print(tab[i]+" ");                    }        System.out.println();               }     public static void main(String[] args) {               int a,b,c;      System.out.println("test unitaire");     System.out.println("test du constructeur");     Pile p=new Pile(3);//creation de instance p           /*test de la fonction getcapacite qui retourne la capacité de la pile       * rentree en parametre      */          a=p.getcapacite();     System.out.println(a);     System.out.println("test ok");     /*test de la fonction estpleine et empiler on test si la pile est      * pleine et si non on peut empiler*/         if(p.estpleine()==false){     p.empiler(1);     }    if(p.estpleine()==false){     p.empiler(3);     }     System.out.println("test ok");          //test de la fonction estvide et getsommet     if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }         if(p.estpleine()==false){     p.empiler(5);     }     System.out.println("test ok");          //test de la fonction affichertab    if(p.estvide()==false){        p.afficherTab();    }     System.out.println("test ok");          //test de la fonction depiler    if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }    if(p.estvide()==false){       c=p.depiler();       p.afficherTab();    }      if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }      if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }    if(p.estvide()==false){       c=p.depiler();       p.afficherTab();    }      if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }       if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }    if(p.estvide()==false){       c=p.depiler();       p.afficherTab();    }      if(p.estvide()==false){         b=p.getsommet();          System.out.println(b);     }           System.out.println("test ok");         }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -