j'ai écrit ce prg en exécutant j' ai les erreurs suivant
Let's play a game,I'll pick a nb between
1 and 100,and you try to guess it
What is your first guess?
50
That's too high Try again
25
That's too high Try again
15
That is too bas, try again
20
That's too high Try again
18
That's too high Try again
16
You didn't get the nb in 6 guesses
You lose.My nb was 17
Would you like to play again
y
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextBoolean(Unknown Source)
at Textprg.Guessingame1.main(Guessingame1.java:15)
aidez moi s'il vous plaît
package Textprg;
import java.util.Scanner;
public class Guessingame1
{
public static void main(String[]args)
{
System.out.println("Let's play a game,I'll pick a nb between");
System.out.println("1 and 100,and you try to guess it");
boolean playagain;
do{
playgame();
System.out.println("Would you like to play again");
Scanner sc=new Scanner(System.in);
playagain=sc.nextBoolean();
}while(playagain);
System.out.println("Thanks for playing.Goodbye.");
}
static void playgame()
{
int computersnb;
int usersguess;
int guesscount=0;
computersnb=(int)(100*Math.random())+1;
System.out.println("");
System.out.println("What is your first guess?");
while(true)
{
Scanner sc1=new Scanner(System.in);
usersguess=sc1.nextInt();
guesscount++;
if(usersguess==computersnb)
{
System.out.println("You get in "+guesscount+" Guesses!My nb was "+computersnb);
break;
}
if (guesscount==6)
{
System.out.println("You didn't get the nb in 6 guesses");
System.out.println("You lose.My nb was "+computersnb);
break;
}
if(usersguess<computersnb)
System.out.println("That is too bas, try again");
else if(usersguess>computersnb)
System.out.println("That's too high Try again");
}
System.out.println("");
}
}
aidez
