• Aucun résultat trouvé

A) Classes associées aux types primitifs

N/A
N/A
Protected

Academic year: 2022

Partager "A) Classes associées aux types primitifs"

Copied!
1
0
0

Texte intégral

(1)

A) Classes associées aux types primitifs

Avec un type primitif, on n'a pas d'objets ni de

méthodes. Grâce aux classes associées (Integer vs int, Double vs double, …), nous pouvons profiter des champs, des méthodes implémentés dans ces classes.

On se limite aux deux classes Integer et Double.

1) Classe Integer associée au type int

// Entier le plus grand:

public final static int MAX_VALUE;

// Entier le plus petit:

public final static int MIN_VALUE;

exemple :

// déterminer l'âge le plus jeune:

int mini = Integer.MAX_VALUE;

for( int i = 0 ; i < age.length ; i++) if ( age[i] < mini) mini = age[i];

/* constructeurs : */

public Integer(int valeur);

public Integer(String s);

exemples :

Integer K = new Integer(23);

Integer Z = new Integer("2345");

/* quelques méthodes : */

public int intValue();

public static int parseInt(String s);

public static Integer valueOf(String s);

exemples (voir aussi les constructeurs):

K.intValue() retourne l'entier 23 (de type int) Integer.parseInt("432") retourne l'entier 432 Integer.valueOf("5678") retourne un objet de la classe Integer dont la valeur "associée" est 5678.

Autres exemples : prochaines pages.

(2)

2) Classe Double associée au type double

// Réel le plus grand:

public final static double MAX_VALUE;

// Réel le plus petit:

public final static double MIN_VALUE;

exemple :

// déterminer la taille la plus grande:

int maxi = Double.MIN_VALUE;

for( int i = 0 ; i < taille.length ; i++) if ( taille[i] > maxi) maxi = taille [i];

/* constructeurs : */

public Double(double valeur);

public Double(String s);

exemples :

Double K = new Double(1.72));

Double Z = new Double("67.8");

K Z

/* quelques méthodes : */

public double doubleValue();

public static Double valueOf(String s);

Autres exemples : prochaines pages.

1.72 67.8

(3)

B) Classe String (chaînes de caractères)

Déclarer et initialiser:

String souhait = "Bonne soirée" ;

String nomPre = new String("Tremblay Pierre");

Souhait nomPre

Quelques méthodes de la classe String :

1. la longueur (le nombre de caractères) :

public int length()

exemples : souhait.length() vaut 12 "A BC".length() vaut 4 2. accès à un caractère à un indice donné

public char charAt(int index)

exemples :

souhait.charAt(0) vaut la lettre 'B' "Bonsoir".charAt(3) vaut la lettre 's' 3. conversion :

public String toLowerCase()

// en minuscules

public String toUpperCase()

// en majuscules exemples :

String nom1 = "Lafleur" ;

String nom2 = nom1.toLowerCase();

nom1 reste "Lafleur" (inchangé) nom2 vaut "lafleur"

String ch = "1er LanGaGe" ; String ch2 = ch.toUpperCase();

ch reste "1er LanGaGe" (inchangé) ch2 vaut "1ER LANGAGE"

"Bonne soirée"

"Tremblay Pierre"

(4)

4. comparaison :

public boolean equals (Object unObjet)

exemples :

"Bon".equals("Bon") vaut true "Bon".equals("bon") vaut false

public boolean equalsIgnoreCase(String autre)

(sans tenir compte de la casse (Maj. vs minuscule) exemples :

"Bon".equalsIgnoreCase("bon") vaut true "Bon".equals("bonsoir") vaut false

public int compareTo(String autre) exemples :

"Bon".compareTo("Bon") vaut 0 (identiques) "Bon".compareTo("Automne") > 0

(la chaîne "Bon" est alors plus grande que la chaîne "Automne")

"Bon".compareTo("Dinde") < 0

(la chaîne "Bon" est alors plus petite que la chaîne "Dinde")

5. recherche :

d'un caractère dans une chaîne :

public int indexOf(char unCar)

exemples :

"Bonsoir".indexOf('n') vaut 2

"Bonsoir".indexOf('z') vaut –1 (non trouvé)

public int lastIndexOf(char unCar)

exemples :

"Bonsoir".lastIndexOf('o') vaut 4

"Bonsoir".lastIndexOf('z') vaut –1 (non trouvé) d'une sous-chaîne dans une chaîne :

public int indexOf(String ch)

exemples :

"Bonsoir".indexOf("soi"') vaut 3

"Bonsoir".indexOf("si") vaut –1 (non trouvé)

public int lastIndexOf(String ch)

exemples :

"Bonsoir".lastIndexOf("oi") vaut 4

"Bonsoir".lastIndexOf("non") vaut –1 (non trouvé)

(5)

6. sous-chaîne:

public String substring(int debut, int fin)

(indice de debut: inclus, indice fin :exclu) exemples :

"Bonsoir".substring(2,6) vaut "nsoi"

"Bonsoir".substring(0, 3) vaut "Bon"

public String substring(int debut)

(à partir de l'indice de debut jusqu'à la fin) exemples :

"Bonsoir".substring(2) vaut "nsoir"

"Bonsoir".substring(4) vaut "oir"

7. etc . . .

//Un exemple sur la classe String

public class TestString {

public static void main(String [] args) {

// déclarer et initialiser quelques chaînes :

String s1 = "bonsoir" , s2 = "bonsoir", s3 = "Bonsoir", s4 = "Tu l'as trop ecrase, Cesar, ce Port-Salut";

int i, j ;

System.out.println("Les 4 chaines originales :");

System.out.println(" s1 = " + s1);

System.out.println(" s2 = " + s2);

System.out.println(" s3 = " + s3);

System.out.println(" s4 = " + s4);

// quelques méthodes fréquemment utilisées :

// public int length() : longueur en nombre de caractères

System.out.println(" longueur de s1 : " + s1.length()+ " caractere(s)");

(6)

// public boolean eaquals(Object autreobjet) : objet est-il égale à 1 autre?

if ( s1.equals(s2))

System.out.println(" s1 a le meme contenu que s2");

else

System.out.println(" s1 n'a pas le meme contenu que s2");

System.out.println(" s1 vs s3 : " + s1.equals(s3));

// public int compareTo (String autre_chaîne) : à parler en classe System.out.println(" s1 vs s3 (encore) : " + s1.compareTo(s3));

// public boolean equalsIgnoreCase(String autre_chaine) : sans distinguer // majuscule et minuscule

if ( s1.equalsIgnoreCase(s3))

System.out.println(" s1 a le meme contenu que s3 sans casse");

else

System.out.println(" s1 n'a pas le meme contenu que s3 (sans casse)");

// public char charAt(indice) : le caractère qui se trouve à l'indice System.out.println("Premier caractere de " + s1 + " est : " +

s1.charAt(0));

System.out.println("Dernier caractere de " + s1 + " est : " + s1.charAt(s1.length() - 1));

// exemple 1 d'utilisation de la méthode charAt System.out.print(s1 + " a l'envers est : ");

for ( i = s1.length() - 1 ; i >= 0 ; i--) System.out.print(s1.charAt(i));

System.out.println();

// méthodes pour extraction de sous-chaînes :

// public String substring (int indice_debut) : à partir de l'indice début System.out.println("s1.substring(3) = " + s1.substring(3));

// public String substring (int indice_debut, int indice_fin) : // à partir de l'indice début jusqu'à (l'indice_fin -1)

System.out.println("s1.substring(3,5) = "+ s1.substring(3,5));

// public int indexOf(int ch) : un caractère se trouve à quel indice System.out.println("le caractere o se trouve a l'indice " +

s1.indexOf('o') + " de " + s1);

// public int indexOf(int ch, int a_partir_indice) :

// à partir d'un indice, un caractère se trouve à quel indice

(7)

System.out.println("un autre caractere o se trouve a l'indice " + s1.indexOf('o',2) + " de " + s1);

System.out.print("Apres avoir fait : s1 = s1.replace('o', 'O'); " + s1 + " devient : ");

// public String replace(char ancien_car, char nouveau_car) s1 = s1.replace('o', 'O');

System.out.println(s1);

// Combien de "on" dans "Bonsoir tout le monde" ? String souhaite = "Bonsoir tout le monde", ch = "on";

int n = 0, indice = 0;

while ( indice >= 0 && indice < souhaite.length()) { indice = souhaite.indexOf(ch, indice);

if (indice >= 0) { n++;

indice++;

} }

System.out.println("On a " + n + " fois du mot on" + " dans " + souhaite);

// il y a autres méthodes mais c'est déjà suffisant pour nous }

}

/* Exécution

Les 4 chaines originales : s1 = bonsoir

s2 = bonsoir s3 = Bonsoir

s4 = Tu l'as trop ecrase, Cesar, ce Port-Salut longueur de s1 : 7 caractere(s)

s1 a le meme contenu que s2 s1 vs s3 : false

s1 vs s3 (encore) : 32

s1 a le meme contenu que s3 sans casse Premier caractere de bonsoir est : b Dernier caractere de bonsoir est : r bonsoir a l'envers est : riosnob s1.substring(3) = soir

s1.substring(3, 2) = so

le caractere o se trouve a l'indice 1 de bonsoir un autre caractere o se trouve a l'indice 4 de bonsoir

Apres avoir fait : s1 = s1.replace('o', 'O'); bonsoir devient : bOnsOir On a 2 fois du mot on dans Bonsoir tout le monde

*/

(8)

C) Lecture des données tapées au clavier

Exemple 1:

/**

* classe Integer

* constante : l'entier le plus grand

* public final static int MAX_VALUE = 2147483647 ; * une des méthodes assez utilisées :

* public static int parseInt(String s);

* exemple : int age = Integer.parseInt("17");

* age vaut 17 * etc ...

*

* classe Double

* un des constructeurs : * public Double (String s) ;

* exemple : Double p = Double("78.2");

* une des méthodes assez utilisées : * public double doubleValue();

* suite de l'exemple :

* double poids = p.doubleValue();

* poids est de type double et sa valeur est 78.2

* VJ++ de Microsoft ne dispose pas de la méthode parseDouble * (qui est disponible avec la version de JDK au labo)

*

* Test de lecture (données tapées au clavier) *

*/

import java.io.*;

public class Utile

{

public static String lireChaine(String message) throws IOException {

BufferedReader entree = new BufferedReader

(new InputStreamReader(System.in));

System.out.print(message);

return entree.readLine();

}

public static char lireCaractere(String message) throws IOException {

return lireChaine(message).charAt(0);

}

public static int lireEntier(String message) throws IOException { return Integer.parseInt(lireChaine(message));

}

(9)

public static double lireReel(String message) throws IOException { /* version pour JDK où la méthode parseDouble existe :

return Double.parseDouble(lireChaine(message));

*/

/* version pour VJ++ où la méthode parseDouble n'existe pas (VJ++ est en retard!

Cette version fonctionne aussi sous JDK */

Double z = new Double (lireChaine(message)) ; return z.doubleValue();

}

// afficher un entier avec tant de colonnes (nbCol) static void afficher(int nombre, int nbCol) { // construire un objet de la classe Integer Integer n = new Integer(nombre);

// convertir en chaîne

String chaine = n.toString();

// afficher des espaces avant

for (int i = 1 ; i <= nbCol-chaine.length() ; i++) System.out.print(" ");

// afficher le nombre

System.out.print(chaine);

} }

// test de la lecture public class TestLecture {

public static void main (String[] args) throws IOException { int age ;

age = Utile.lireEntier("Entrez l'age de la personne ");

System.out.println("Age lu : " + age);

double taille = Utile.lireReel("Entrez la taille en metre ");

System.out.println("Taille lue : " + taille);

char sexe = Utile.lireCaractere("Entrez f,F, m ou M pour le sexe ");

System.out.println("sexe lu : " + sexe);

String nomPre = Utile.lireChaine("Entrez le nom et prenom ");

System.out.println("Nom et prenom lu : " + nomPre);

System.out.println("Nom et prenom en majuscules : " + nomPre.toUpperCase());

} }

(10)

/* Exécution :

Entrez l'age de la personne 21 Age lu : 21

Entrez la taille en metre 1.72 Taille lue : 1.72

Entrez f,F, m ou M pour le sexe m sexe lu : m

Entrez le nom et prenom Jean Trepanier Nom et prenom lu : Jean Trepanier

Nom et prenom en majuscules : JEAN TREPANIER

*/

Exemple 2 : /*

* Notez que les méthodes lireEntier, lireCaractere, ... sont "static"

* => l'accès à ces méthodes via le nom de la classe (dans cet exemple * la classe Utile

* Ce programme permet de saisir le rang d'un mois (1 pour janvier, * 2 pour février, ..., 12 pour décembre).

* On détermine et affiche le mois, son nombre de jours (28, 29, 30 ou 31) * ou affiche un message approprié.

* Le programme fonctionne tant que l'usager décide de continuer.

* Matières pour l'exemple :

* - lecture de données tapées au clavier * - méthodes "static"

* - révision de if, switch, opérateurs */

import java.io.*;

public class Bissextile {

public static void main (String[] args) throws IOException { int rang, nbJours = 31;

String[] mois = { "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre",

"Novembre", "Decembre" };

char reponse ; do {

// saisir le rang du mois tapé au clavier

rang = Utile.lireEntier("Entrez le rang d'un mois entre 1 et 12 ");

// déterminer le nombre de jours if (rang < 1 || rang > 12)

System.out.println("Le rang " + rang + " est errone ");

else {

switch (rang) {

case 1 : case 3 : case 5 : case 7 :

(11)

case 8 : case 10 : case 12 : nbJours = 31; break;

case 4 : case 6 : case 9 : case 11 : nbJours = 30; break;

case 2 : // mois de février, 28 ou 29 jours int annee = Utile.lireEntier("Entrez l'annee (ex. 2001) ");

int an = annee % 100, siecle = annee / 100 ; // cas des années avec 29 jours au février :

if ( (an > 0 && an % 4 == 0) || (an == 0 && siecle % 4 == 0) ) nbJours = 29;

else // 28 jours

nbJours = 28;

}

System.out.print("Le mois ");

if (rang == 4 || rang == 8 || rang == 10) System.out.print("d'");

else System.out.print("de ");

System.out.println(mois[rang-1] + " a " + nbJours + " jours");

}

reponse = Utile.lireCaractere("Voulez-vous continuer ? (o/n) ");

}while ( reponse == 'o' || reponse == 'O') ; }

}

/* Exécution :

Entrez le rang d'un mois entre 1 et 12 -7 Le rang -7 est errone

Voulez-vous continuer ? (o/n) o

Entrez le rang d'un mois entre 1 et 12 4 Le mois d'Avril a 30 jours

Voulez-vous continuer ? (o/n) o

Entrez le rang d'un mois entre 1 et 12 10 Le mois d'Octobre a 31 jours

Voulez-vous continuer ? (o/n) o

Entrez le rang d'un mois entre 1 et 12 2 Entrez l'annee (ex. 2001) 2001

Le mois de Fevrier a 28 jours Voulez-vous continuer ? (o/n) o

Entrez le rang d'un mois entre 1 et 12 2 Entrez l'annee (ex. 2001) 2004

Le mois de Fevrier a 29 jours Voulez-vous continuer ? (o/n) n

*/

(12)

D) Format d'affichage

/* Pour présenter "un peu" des résultats Utile pour les TPs

Aucune question sur le formatage aux examens

*/

import java.text.DecimalFormat; // format des réels public class TestFormat

{

// afficher un entier avec tant de colonnes (nbCol)

static void afficher(int nombre, int nbCol) {

// construire un objet de la classe Integer Integer n = new Integer(nombre);

// convertir en chaîne

String chaine = n.toString();

// afficher des espaces avant

for (int i = 1 ; i <= nbCol-chaine.length() ; i++) System.out.print(" ");

// afficher le nombre System.out.print(chaine);

}

public static void main (String[] args)

{

// test d'affichage des entiers avec format int age = 25 ;

for (int k = 1 ; k <= 10 ; k++) {

afficher(age, k);

System.out.println();

}

// test d'affichage des réels avec format

int nbPieds = 5, nbPouces = 9 ; // 5 pieds, 9 pouces double taille = (5 + 9 / 12.0) * 0.3048 ;

System.out.println("La taille : " + taille + " metre (sans format)");

(13)

/* construire un objet de la classe DecimalFormat

apliquer ensuite la méthode "format" sur l'objet fmt qu'on vient de construire

*/

DecimalFormat fmt = new DecimalFormat("0.00");

System.out.println("La taille : " + fmt.format(taille) + " metre (avec format 0.00)");

fmt = new DecimalFormat("0.0");

System.out.println("La taille : " + fmt.format(taille) + " metre (avec format 0.0)");

fmt = new DecimalFormat(" 0.00");

System.out.println("La taille : " + fmt.format(taille) + " metre (avec format 0.00 (espaces avant))");

}

}

/* Exécution : 25

25 25 25 25 25 25 25 25 25

La taille : 1.7526000000000002 metre (sans format) La taille : 1,75 metre (avec format 0.00)

La taille : 1,8 metre (avec format 0.0)

La taille : 1,75 metre (avec format 0.00 (espaces avant))

*/

(14)

Classe prédéfinie String (chaîne de caractères).

Ce document est adapté à partir du document de la compagnie SUN qui se trouve sur le lien :

http://java.sun.com/products/jdk/1.2/docs/api/index.html

J’ai ajouté quelques exemples permettant de comprendre les constructeurs et quelques méthodes utiles de cette classe.

Comme la classe String fait partie du paquet java.lang (langage Java), on n’a pas besoin d’importer.

La plupart des questions des travaux pratiques utilisent la classe prédéfinie String.

Quelques constructeurs

String()

Initializes a newly created String object so that it represents an empty character sequence.

Exemple : String ch = new String(); // ch est une chaîne vide (aucun caractère) String(String value)

Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words,

the newly created string is a copy of the argument string.

Exemple : String nomPre = new String("Charbonneau Jacques");

NomPre est la chaîne de caractères "Charbonneau Jacques"

etc . . .

Quelques méthodes

char charAt(int index)

Returns the character at the specified index (retourne le caractère à tel indice)

Exemple : "Charbonneau Jacques".charAt(0) vaut ‘C’ et

"Charbonneau Jacques".charAt(1) vaut ‘h’

int compareTo(String anotherString) Compares two strings lexicographically.

Exemple : "Bon".compareTo("Bal") retourne un entier supérieur à zéro car ‘o’ > ‘a’

(dans l’ordre alphabétique)

"Bon" > "Bal"

"BON".compareTo("Bon") retourne un entier inférieur à zéro car ‘O’ < ‘o’

(les lettres en majuscules ‘A’, ‘B’, …, ‘O’, … se trouvent avant celles en minuscules ‘a’, ‘b’, …, ‘o’, …

"BON" < "Bon"

"BON".compareTo("BON") retourne zéro (les deux chaînes sont identiques)

boolean equals(Object anObject)

Compares this string to the specified object.

Exemple : "Bon".equals("Bal") retourne false et "Bon".equals("Bon") retourne true

(15)

boolean equalsIgnoreCase(String anotherString)

Compares this String to another String, ignoring case considerations.

Exemple : "Bon".equals("BON") retourne false mais

"Bon".equalsIgnoreCase("BON") retourne true (sans distinguer majuscules, minuscules).

int indexOf(int ch)

Returns the index within this string of the first occurrence of the specified character.

Exemple : "Bonbon".indexOf(‘n’) retourne 2 et "Bonbon".indexOf(‘z’) retourne – 1 (non trouvé)

int indexOf(int ch, int fromIndex)

Returns the index within this string of the first occurrence of the specified character, starting the search at the

specified index.

Exemple : "Bonbon".indexOf(‘n’, 3) retourne 5 et "Bonbon".indexOf(‘b’, 4) retourne –1 (non trouvé)

int indexOf(String str)

Returns the index within this string of the first occurrence of the specified substring.

Exemple : "Bonbon".indexOf(" on") retourne 1 et "Bonbon".indexOf(" onze") retourne –1 (non trouvé)

int indexOf(String str, int fromIndex)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified

index.

int lastIndexOf(int ch)

Returns the index within this string of the last occurrence of the specified character.

Exemple : "Bonbon".lastIndexOf(‘n’) retourne 5 et "Bonbon".lastIndexOf(‘z’) retourne –1 (non trouvé)

int lastIndexOf(int ch, int fromIndex)

Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

int lastIndexOf(String str)

Returns the index within this string of the rightmost occurrence of the specified substring.

int lastIndexOf(String str, int fromIndex)

Returns the index within this string of the last occurrence of the specified substring.

int length()

Returns the length of this string (retourne la longueur de la chaîne) Exemple : "Bonbon".length() retourne 6 (la longueur de la chaîne est 6) Ne pas oublier les parenthèses pour la méthode length()

String replace(char oldChar, char newChar)

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

boolean startsWith(String prefix)

Tests if this string starts with the specified prefix.

(16)

boolean startsWith(String prefix, int toffset)

Tests if this string starts with the specified prefix beginning a specified index.

String substring(int beginIndex)

Returns a new string that is a substring of this string.

Exemple : "Bonbon".substring(2) retourne la sous-chaîne "nbon"

String substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string.

Exemple : "Bonbon".substring(2, 4) retourne la sous-chaîne "nb" (indice 2 inclus, indice 4 exclu !)

String toLowerCase()

Converts all of the characters in this String to lower case using the rules of the default locale, which is

returned by Locale.getDefault.

conversion toute la chaîne en lettres minuscules.

Exemple : "Bonbon".toLowerCase() retourne la chaîne "bonbon"

String toString()

This object (which is already a string!) is itself returned.

String toUpperCase()

Converts all of the characters in this String to upper case using the rules of the default locale, which is returned by Locale.getDefault.

Exemple : "Bonbon".toUpperCase() retourne la chaîne "BONBON"

String toUpperCase(Locale locale)

Converts all of the characters in this String to upper case using the rules of the given locale.

String trim()

Removes white space from both ends of this string.

Exemple : " Bonjour tout le monde ".trim() retourne la chaîne "Bonjour tout le monde ".trim()

static String valueOf(boolean b)

Returns the string representation of the boolean argument.

static String valueOf(char c)

Returns the string representation of the char argument.

static String valueOf(char[] data)

Returns the string representation of the char array argument.

static String valueOf(char[] data, int offset, int count)

Returns the string representation of a specific subarray of the char array argument.

static String valueOf(double d)

Returns the string representation of the double argument.

static String valueOf(float f)

Returns the string representation of the float argument.

static String valueOf(int i)

Returns the string representation of the int argument.

static String valueOf(long l)

(17)

Returns the string representation of the long argument.

static String valueOf(Object obj)

Returns the string representation of the Object argument.

Classe prédéfinie Integer (objets associés aux entiers).

Ce document est adapté à partir du document de la compagnie SUN qui se trouve sur le lien : http://java.sun.com/products/jdk/1.2/docs/api/index.html

J’ai ajouté quelques exemples permettant de comprendre les constructeurs et quelques méthodes utiles de cette classe.

Comme la classe Integer fait partie du paquet java.lang (langage Java), on n’a pas besoin d’importer.

Quelques exemples du cours IFT 1170 utiliseront la classe prédéfinie Integer.

Pourquoi a t-on besoin de la classe Integer ? - pour utiliser ses champs prédéfinis

- pour appliquer des méthodes appropriées sur leurs objets.

Quelques champs d’information :

static int MAX_VALUE

The largest value of type int.

Integer.MAX_VALUE est une constante de la classe Integer. Elle représente l’entier le plus grand 2147483647

static int MIN_VALUE

The smallest value of type int.

Integer.MIN_VALUE est une constante de la classe Integer. Elle représente l’entier le plus petit -2147483648

Constructeurs

Integer(int value)

Constructs a newly allocated Integer object that represents the primitive int argument.

Exemple : Integer z = new Integer(12) ; z est un objet de la classe Integer représentant l’entier 12

Integer(String s)

Constructs a newly allocated Integer object that represents the value represented by the string.

Exemple : Integer z = new Integer("432") ; z est un objet de la classe Integer représentant l’entier 432

(18)

Quelques méthodes utiles

boolean equals(Object obj)

Compares this object to the specified object.

float floatValue()

Returns the value of this Integer as a float.

int intValue()

Returns the value of this Integer as an int.

static int parseInt(String s)

Parses the string argument as a signed decimal integer.

String toString()

Returns a String object representing this Integer's value.

static Integer valueOf(String s)

Returns a new Integer object initialized to the value of the specified String.

Notez que l’affectation int age = Integer.parseInt(“27“) ; affecte à la variable age la valeur 27

Soit le tableau des ages : int age[] = { 25, 12, 70, 97, 12, 40, 28 };

Le bloc d’instructions suivantes permettant de déterminer et d’afficher l’âge le plus grand :

int ageMax = Integer.MIN_VALUE;

for (int i = 0 ; i < age.length ; i++) if ( age[i] > ageMax )

ageMax = age[i];

System.out.println("Age maximum : " + ageMax);

Références

Documents relatifs

In the former case, a failed lookup should return zero (since Smalltalk indices are one-based); in the latter case, one past the last valid index signifies that the whole string

Say we want to cover a clause using the factor corresponding to v 2 1 : the coherence gadgets will force us to use the strings corresponding to ¬v 1 1 , ¬v 2 1 , and ¬v 3 1 to cover

We face a double dilemma, for both symmetric and asymmetric relations:

Within the framework of likelihood inference, there are two quantities we must evaluate: What is the probability that there would be as much evil as there is, if the universe

The upper bound is achieved by analysis of Lyndon words (i.e. words that are primitive and minimal/maximal in the class of their cyclic equivalents) that appear as periods of cubic

cases are considered : the diffraction of an incident plane wave in section 3 and the case of a massive static scalar or vector field due to a point source. at rest

on weak factorization systems from the realm of locally presentable categories to all locally ranked categories. We use

Toute utili- sation commerciale ou impression systématique est constitutive d’une infraction pénale.. Toute copie ou impression de ce fichier doit conte- nir la présente mention