#how do I make an input only allow integers, and also in word form e.g. ten

3 messages · Page 1 of 1 (latest)

vital wyvern
#

import javax.swing.*;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        short age;
        age = 12;
        System.out.println("What's your name?");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("Ok " + name);
        System.out.println("I am " + age + " years old");
        System.out.println("How about you");
        int input = scanner.nextInt();
        //convert string to int
        //if less than 10 li'l baby man
        if (input <= 9) {
            System.out.println("Ha ha ha");
            System.out.println("Li'l baby");
            TimeUnit.SECONDS.sleep(1);
            System.out.println("Li'l baby man");
        }

        //if between 50 and 10
        if (input >= 10) {
            if (input <= 49) {

                System.out.println("Gen Z");
                System.out.println("*insert Gen Z humor here*");
            }}

        //if 69 gay
        if (input == 69) {
            System.out.println("why did you just type " + input);
            System.out.println("You are so dirty minded...");
            TimeUnit.SECONDS.sleep(1);
            System.out.println(name + " gay");
        }



            //if more than 50 and less than 100 but not 69 boomer
            if (input >= 50) {
                if (input <= 99) {
                    if (input != 69) {
                     System.out.println("BOOMER ALERT");
                    TimeUnit.SECONDS.sleep(1);
                    System.out.println("BOOMER IN AISLE 2");
            }}}

            //if more than 100 old timer
        if (input >= 100) {
            System.out.println("bro's a highlander💀");
        }


        }
    }

I want it to instead of coming up with an error, say: sorry that's not a integer, please try again

queen irisBOT
#

This post has been reserved for your question.

Hey @vital wyvern! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.