Menu

#832 Exercise 22 -Password

closed
nobody
None
2016-03-17
2016-02-17
Anonymous
No

Hi
I tried solving Ex 22. The test compiles and the output was as expected. But it did not pass the test on server.
I dont get whats the error.Could you please help.
I submitted the following code:

import java.util.Scanner;

public class Password {

public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);
    String password = "carrot"; // Use carrot as password when running tests.

    while(true)
    {
    System.out.println("Type the password: ");
    String x = reader.nextLine();

    if(x.equals("carrot"))
    {
        System.out.println("Right!");
        System.out.println("The secret is: jryy qbar!");
    }

    else
    {
        System.out.println("Wrong!");
    }

    System.out.println("The secret is: jryy qbar!");

    }
}

}

Discussion

  • Jarmo

    Jarmo - 2016-02-17

    Hey, the proper place to ask help about code is nowadays our IRC channel and our Google groups. and sharing code is easier when using out pastebin service: In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it here.

    Anyways, now your code prints se secret anyway, not depending on whether the password was entered properly.

     
  • ljleppan

    ljleppan - 2016-03-17
    • status: open --> closed
     
MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.