0

I am trying to write a program that takes input from the user using a scanner, but then i need to sometimes randomise the user input and check if its true or false.

the output needs to look something like this

Enter word to be tested: Name

Is anem the same as : Name - False

Enter the word to be tested: Rothschild

Is Rothschild the same as: Rothschild - True

Now I am very new to Java and have no idea how to put it all together. Im trying to use a scanner, arraylist and the random util but am struggling to get the code figured out.

Any advice for clarity on how to write this program is much appreciated.

1 Answers1

0

I don't understand what you mean when you say "but then i need to sometimes randomise the user input and check if its true or false."

To get you started, you can look up how to user the Scanner class here.

To find whether the user input is the same as the string you want to compare it with, using the string method .equalsIgnoreCase()

    Scanner scan = new Scanner(System.in);
    System.out.println("Enter input...");
    String userStr = scan.nextLine();
    String compareStr = "Hello World";

    System.out.println("User input: " + userStr);
    System.out.println("Is \"" + compareStr + "\" the same as \"" + userStr + "\" : " + userStr.equalsIgnoreCase(compareStr));

Output: User input: Hello
Is "Hello World" the same as "Hello" : false

codemonkey
  • 58
  • 1
  • 8
  • its just in this case how am i going to know what the user input is? it could be anything. So how would you code a program to take that users input and not only print it out exactly as typed but to also make some print with randomly jumbled letters? as shown in the example – Stew-coder95 Nov 08 '17 at 14:18
  • [Link](https://stackoverflow.com/questions/20588736/how-can-i-shuffle-the-letters-of-a-word), sorry for the late response. – codemonkey Nov 16 '17 at 23:20