Int en string ??
Résolu
studentjava
Messages postés
12
Statut
Membre
-
studentjava Messages postés 12 Statut Membre -
studentjava Messages postés 12 Statut Membre -
import java.util.Scanner;
public class nomResultats {
public static void main(String args []) {
int max = Integer.MIN_VALUE;
int i;
for (i=1; i<=3; i++){
System.out.println("paticipant numero " +i+ " entrez votre nom");
Scanner scanner = new Scanner(System.in);
String nom = scanner.nextLine();
System.out.println("entrez le resultat obtenue " +i);
int resultat = scanner.nextInt();
if (resultat>max){
max = resultat;
}
}
}
}
comment afficher le nom du meuilleur participant
1 réponse
-
Bonjour,
System.out.println(max);
par exemple ?
Je ne vois pas où est le problème en fait...-
-
Tu as changé ta question après ma réponse...
Si tu veux afficher le nom du participant il faut le stocker au moment où tu calcules ton max.
if (resultat>max) { max = resultat; nomMax = nom; }
Et à la fin de ton code :System.out.println(nomMax);
Mais ça n'a rien à voir avec de la conversion d'int en String qu'indique ton titre... -
-
import java.util.Scanner;
public class nomResultats {
public static void main(String args []) {
int max = Integer.MIN_VALUE;
int i;
for (i=1; i<=3; i++){
System.out.println("paticipant numero " +i+ " entrez votre nom");
Scanner scanner = new Scanner(System.in);
String nom = scanner.nextLine();
System.out.println("entrez le resultat obtenue " +i);
int resultat = scanner.nextInt();
if (resultat>max) {
max = resultat;
nomMax = nom;
}
System.out.println("le meuilleur participant est "+nomMax);
}
}
}
pourquoi il me dit que nomMax n'est pas defni ? -
-