samedi 22 août 2015

The program skip clavier.nextLine

Please, when i answer the question: Do you have more than 18years it directly say :
-you are a adult
-create your password
-please create a password between 6 and 10 letters

but i can't answer this questions.

when i delete the question: Do you have more than 18 years? (Yes/No)

the program work perfectly.

import java.util.Scanner;
class mmm
{

public static void main (String[] args) {
Scanner clavier= new Scanner(System.in); 
String name;
String password;
String time;
char adult  ;

System.out.println("Hello,create your username:\t");
name=clavier.nextLine();
System.out.println("Welkom "+name);







System.out.println
("Do you have more than 18 years? (Yes/No)");

    adult= clavier.findWithinHorizon(".", 0).charAt(0);

if (adult=='y'|| adult=='Y')
{
    System.out.println("you are adult");
}
else
{
    System.exit(0); 

}








System.out.println("create your password:\t");

password= clavier.nextLine();

  while( (password.length() < 6) || (password.length() > 10) )  
{
System.out.println
("please create a password between 6 and 10 letters");
    password=clavier.nextLine();
}

String  password2;
System.out.println("Please write your password again");
password2 = clavier.nextLine();
while( !password2.equals(password) )
{
    System.out.println("your passwords aren't the same");
    password2=clavier.nextLine();
}
System.out.println("acount create");





}   
}

Aucun commentaire:

Enregistrer un commentaire