Exercices de Programmation en Java (Tableaux Et Methodes)

download Exercices de Programmation en Java (Tableaux Et Methodes)

of 17

Transcript of Exercices de Programmation en Java (Tableaux Et Methodes)

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    1/17

    /*

    * To change this license header, choose License Headers in Project Properties.

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package tableaux;

    /**

    *

    * @author Ben

    */

    public class Exemple_1 {

    public static void main(String[] args){

    int tab1[]={1,2,3,4,5};

    int [] tab2={6,7,8,9,10};

    System.out.println("Afficher de tab1: ");

    for(int i=0; i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    2/17

    * and open the template in the editor.

    */

    package tableaux;

    /**

    *

    * @author Ben

    */

    public class Exemple_2 {

    public static void main(String[] args){

    char [] tab={'a','b','c','d','f','g','h','i','j','l'};

    System.out.println("Affichage des tableaux de : ");

    for(int i=0; i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    3/17

    public static void main(String[] args){

    String [] jour={"lundi","mardi","mercredi","jeudi","samedi","dimanche"};

    System.out.println("Affichage de tableaux du jour: ");

    for(int i=0; i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    4/17

    System.out.println("Initialisation du tableau: ");

    for(int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    5/17

    int[] tab;

    System.out.println("Ce programme initialiser et affiche un tableaux: ");

    System.out.println("Donner la taille du tableaux: ");

    taille=sc.nextInt();

    tab =new int[taille];

    System.out.println("Initialisation du tableau: ");

    for(int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    6/17

    public static void main(String [] args){

    int [][] tab={{1,11,12,13,14,15}

    ,{2,21,22,23,24,25}

    ,{3,31,32,33,34,35}

    };

    System.out.println("Ce programme affiche un tableau unitialiser: ");

    for(int i=0; i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    7/17

    int [][] tab={{1,11,12,13,14,15}

    ,{2,21,22,23,24,25}

    ,{3,31,32,33,34,35}

    };

    System.out.println("Ce programme affiche un tableau unitialiser: ");

    for(int i=0; i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    8/17

    */

    public class Exemple_8 {

    public static void main(String[] args){

    Scanner sc=new Scanner(System.in);

    int [][] tab;

    int lign, col;

    System.out.println("ce programme initialise et affiche une matrice d'entier: ");

    System.out.println("Donner le nbre de ligne: ");

    lign=sc.nextInt();

    System.out.println("Donner le nbre de colonne: ");

    col=sc.nextInt();

    tab=new int [lign] [col];

    System.out.println("Initialisation de la matrice: ");

    for(int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    9/17

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package tableaux;

    import java.util.Scanner;

    /**

    *

    * @author Ben

    */

    public class Exemple_9 {

    public static void main(String[] args){

    Scanner sc=new Scanner(System.in);

    int [][] tab;

    int lign,min,col;

    System.out.println("ce programme initialise et affiche une matrice d'entier: ");

    System.out.println("Donner le nbre de ligne: ");

    lign=sc.nextInt();

    System.out.println("Donner le nbre de colonne: ");

    col=sc.nextInt();

    tab=new int [lign] [col];

    System.out.println("Initialisation de la matrice: ");

    for(int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    10/17

    for(int j=0;j

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    11/17

    Scanner sc=new Scanner(System.in);

    int [] tab;

    int taille,tmp;

    System.out.println("Inversion du tableaux: ");

    System.out.println("Initialisation de tableaux a inverser: ");

    System.out.println("Donner la taille du tableaux: ");

    taille=sc.nextInt();

    tab=new int[taille];

    for(int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    12/17

    /*

    * To change this license header, choose License Headers in Project Properties.

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package methodes;

    import java.util.Scanner;

    /**

    *

    * @author PAPI SARR

    */

    public class Exemple_2 {

    public static void main(String[] args ){

    Scanner sc=new Scanner(System.in);

    System.out.println("Donner la taille du tableau a initialiser");

    int taille=sc.nextInt();int []tab=new int[taille];

    inittab(tab);

    affichetab(tab);

    System.out.println("\nLe minimun du tableau est "+mintab(tab));

    }

    public static void inittab(int []tab){

    Scanner sc=new Scanner (System.in);

    System.out.println("Initialisation du tableau");

    for (int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    13/17

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    14/17

    * @author PAPI SARR

    */

    public class Exemple_4 {

    public static void main(String[] args){

    Scanner sc=new Scanner(System.in);

    System.out.println("Donner un entier: ");

    int a=sc.nextInt();

    System.out.println("Donner un autre entier: ");

    int b=sc.nextInt();

    System.out.println("le produit de "+a+" et "+b+" est "+produit(a,b));

    }

    public static int produit(int n,int m){

    int res=n*m;

    return res;

    }

    }

    /** To change this license header, choose License Headers in Project Properties.

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package methodes;

    import java.util.Scanner;

    public class Exemple_5 {

    public static void main(String[] args){

    Scanner sc=new Scanner(System.in);

    float x,y;

    System.out.println("operation sur deux nombres: ");

    System.out.println("Donner le premier nombre: ");

    x=sc.nextFloat();

    System.out.println("Donner le second nombre: ");

    y=sc.nextFloat();

    operation(x,y);

    }////////////////////////////////////////////////////////

    public static void operation(float a,float b){

    Scanner sc=new Scanner(System.in);

    int choix,rep;

    float res;

    do{

    System.out.println("Ce programme opere dux nombres");

    System.out.println("Choisir un opration: ");

    System.out.println("1- Addition");

    System.out.println("2-Soustraction");

    System.out.println("3-Multiplication");

    System.out.println("4-Division");

    System.out.println("Entre le numero de votre choix");

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    15/17

    choix=sc.nextInt();

    System.out.println("Confirmer votre choix! 1 si oui, un aute chiffre sinon");

    rep=sc.nextInt();

    }while(rep!=1);

    switch(choix){

    case 1:

    res=a+b;

    System.out.println(a+"+"+b+"="+res);break;

    case 2:

    res=a-b;

    System.out.println(a+"-"+b+"="+res);break;

    case 3:

    res=a*b;

    System.out.println(a+"*"+b+"="+res);break;

    case 4:

    if(b==0)

    {System.out.println("Le division par zero n'existe pas");

    }

    else

    {

    res=a/b;

    System.out.println(a+"/"+b+"="+res);

    }

    break;

    }

    }

    }

    .

    /*

    * To change this license header, choose License Headers in Project Properties.

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package methodes;

    import java.util.Scanner;

    public class Exemple_6 {

    public static void main(String[] args ){

    Scanner sc=new Scanner(System.in);

    System.out.println("Donner la taille du tableau a initialiser");

    int taille=sc.nextInt();

    int []tab=new int[taille];

    inittab(tab);

    System.out.println("\nLe minimun du tableau est "+mintab(tab));

    }

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    16/17

    public static void inittab(int []tab){

    Scanner sc=new Scanner (System.in);

    System.out.println("Initialisation du tableau");

    for (int i=0;i

  • 8/9/2019 Exercices de Programmation en Java (Tableaux Et Methodes)

    17/17

    if(min>tab[i])

    min=tab[i];

    }

    return min;

    }

    }

    /** To change this license header, choose License Headers in Project Properties.

    * To change this template file, choose Tools | Templates

    * and open the template in the editor.

    */

    package methodes;

    import java.util.Scanner;

    public class Exemple_7 {

    public static void main(String[] args ){Scanner sc=new Scanner(System.in);

    double caa=0;

    String representant;

    System.out.println("Donner le nom du representant: ");

    representant=sc.nextLine();

    chiffdaffaire(representant,caa);

    }

    ////////////////////////////////////////////////////////////////////////////

    public static void chiffdaffaire(String representant,double caa){

    Scanner sc=new Scanner(System.in);

    double cam;

    for(int i=1;i