0

Basically i want to confirm that your name that you typed is correct im not really sure what the issue is as im new to java and only started to properly take the time to learn code recently, any suggestions thanks and sorry for the bad code im new to this.

import java.util.Scanner;

import java.util.concurrent.TimeUnit;

public class Username {

@SuppressWarnings({ "unused", "resource" })
public static void main(String[] args) throws InterruptedException {


    //This is where you are told to enter your name

    @SuppressWarnings({"resource", "unused"})
    Scanner sc = new Scanner(System.in);

    System.out.println("Enter your name: ");



    @SuppressWarnings("resource")

    // This is where you enter your name
    Scanner scanner = new Scanner(System.in);
    // Your name is then saved as a string so it can be called with "name"
    String name = scanner.nextLine();


    System.out.println("Hello " + name + " lets begin.");



    // This is confirming that your name is correct
    {

        TimeUnit.SECONDS.sleep(2);
    System.out.println("For a test your name is " + name + " correct?");

    // This is the input for confirming your name
    Scanner confirm = new Scanner(System.in);
    String confirmation = scanner.nextLine();
            boolean istrue = true;

    // Meant to print out a line if its = to Yes not working atm
    if(istrue = true){

        System.out.println("Good lets continue");

    }


    }

}

}

1 Answers1

0

Try this code.

 Scanner confirm = new Scanner(System.in);
    String confirmation = scanner.nextLine();

    // Meant to print out a line if its = to Yes not working atm
    if(confirmation.equals("yes")){

        System.out.println("Good lets continue");

    }
Sahil
  • 553
  • 1
  • 5
  • 23
  • That works thanks, i was able to write this but your system seems more straight forward thanks `// Meant to print out a line if its = to Yes not working atm /* String Yes = "Yes"; String Yeah = "Yeah"; scanner.findInLine(Yes); scanner.findInLine(Yeah); System.out.println("Good lets continue"); } */ // System.out.println(Yes); }` – Dylan Hussain Mar 17 '19 at 07:26
  • you need to read more about string comparision. follow this link https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java , And if you found this answer useful mark it answer and upvote – Sahil Mar 17 '19 at 07:29