0

Hi I'm newbie in Java and I have to write a code which simulate logging to bank account and I want to allow user to press enter key to continue after "inserting" card instead of pressing alphabetic key

public class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("If you inserted card press y"); 
        String p = sc.nextLine();
        boolean tak;

        if (p.charAt(0) == 'Y' || p.charAt(0) == 'y')
            tak = true;
        else
            tak = false;

        Loginning l = new Loginning(tak);
    }
}

Also after pressing enter 'tak' boolean needs to return true like in the if statement

JustAFellowCoder
  • 294
  • 1
  • 11
litseba
  • 7
  • 4
  • 1
    If you only wanted the [Enter] key itself to be used, then you could look for a blank `String` instead of `Y` (`p.equals("")`). Otherwise, you could simply ignore the check altogether (and the input) and simply proceed regardless of what they entered – MadProgrammer Mar 26 '19 at 19:53
  • thanks, I was thinking about empty string (or char) but i had to put space before enter to have it working. I didn't know about equals method, thanks again – litseba Mar 26 '19 at 20:03

0 Answers0