Q:

java keep looping if user input is not an integer

I have tried similar codes in this site but nothing works for me. So I want the program to keep asking the user to input an integer if its not integer. If the credit card is integer then go to expiration date and if it is valid then print invoice. I tried if and while loop, also try and catch but I guess my logic is broken. Any help will be appreciated.
    Scanner s = new Scanner(System.in);
    System.out.println("Type 'quit' to exit payment");
    System.out.println("Enter name: ");
    String name = s.next();
    s.nextLine();

    if (name.equals("quit"))
    {
        return;
    }

    System.out.println("Enter address: ");
    String address = s.nextLine();

    if (address.equals("quit"))
    {
        return;
    }

    System.out.println("Type '000' to exit payment");
    System.out.println("Enter card number: ");
    @override
    int cardNo = s.nextInt();
    if (cardNo == 000) 
    {
        return;
    }

    System.out.println("Enter card expiration date: (DDMMYY)");
    int expirationDate = s.nextInt();

    if (expirationDate == 000)
    {
        return;
    }

    //if input is ok then printing invoice
}

A:

Try the following, I'll also note a few things afterwards about quitting your application
Scanner s = new Scanner(System.in);
String name = "", address = "";
int cardNo = 0, expirationDate = 0;

while(name == "" || address == "" || cardNo == 0 || expirationDate == 0)
{ 
    System.out.println("Type 'quit' to exit payment");

    //Get Name
    System.out.print("Enter name: ");
    name = s.nextLine();
    if (name.equals("quit")){return;}

    //Get address
    System.out.print("Enter address: ");
    address = s.nextLine();
    if (address.equals("quit")){return;}

    System.out.println("Type '-1' to exit payment");

    //Get card number continually until an integer is entered
    do {
        System.out.print("Enter card number: ");
        try {
            cardNo = Integer.parseInt(s.nextLine());
            break;
        } catch (Exception e) {
            continue;
        }
    } while (true);
    if (cardNo == -1) {return;}

    //Get card expiration date continually until an integer is entered
    do {
        System.out.println("Enter card expiration date: (DDMMYY)");
        try {
            expirationDate = Integer.parseInt(s.nextLine());
            break;
        } catch (Exception e) {
            continue;
        }
    } while (true);
    if (expirationDate == -1){return;}
}

You might have noticed I changed what to enter when quitting at the card number and expiration date part of the program from 000 to -1. This is because 000 converted to an int will have the value of 0, so the user would never be able to exit your application. 

