Source de Prog19.java
class Prog19 {
public static void main (String args[]) {
int [] tab;
int nbre, i, max;
tab = new int[5];
tab[1]= 45; tab[3]= 412;
tab[0]= 3; tab[2]= 5; tab[4]= 0;
System.out.println("le nombre d'element"
+ " du tableau = " + tab.length);
i=1; max=tab[0];
while (i < tab.length){
if (tab[i]>max)
max = tab[i] ;
i = i+1;
}
System.out.println("le maximun est "
+ max);
}
}
|
le nombre d'element du tableau = 5 le maximun est 412 |
| indice : | 0 | 1 | 2 | 3 | 4 |
| élément | 3 | 45 | 5 | 412 | 0 |
type [] nomDeTableau;
type nomDeTableau[] ; tableau = new type[nombre]; tableau.length =
le nombre d'éléments déclaré.tableau.length
- 1)
int tab[] = {3,45,5,412,0};
Source de Prog22.java
/* crée puis affiche ligne par ligne
la matrice identité de réels 3-3
*/
class Prog22 {
public static void main (String args[]) {
double ident[][];
int i,j;
ident = new double[3][3];
for (i=0; i<3 ; ++i)
for (j=0; j<3 ; ++j)
if (i ==j )
ident[i][j]=1.0;
else
ident[i][j]=0.0;
System.out.println("matrice identité :");
for (i=0; i<ident.length ; ++i)
{
for (j=0; j<ident[0].length ; ++j)
System.out.print(ident[i][j]+" ");
System.out.println();
}
}
}
|
matrice identité : 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 |
type [][] nomDeMatrice;
type nomDeMatrice[][] ;
matrice = new type[nombre1][nombre2];
matrice.length =
la première (ou encore le nombre de lignes)matrice[0].length =
la seconde (ou encore le nombre de colonnes)
double matriceNulle [] [] = {{0,0,{0,0}};
Source de Prog23.java
class Prog23 {
public static void main (String args[]) {
int i;
System.out.println("les arguments :");
for (i=0; i<args.length ; ++i)
System.out.println(args[i]);
}
}
|
$ java Prog23 1.0 "hello world" "et" 4X les arguments : 1.0 hello world et 4X |
String args[] est un tableau de chaînes caractères,
autant que de paramètres passés
java programme parametre1 parametre2