Skip to content
Advertisement

How to get my scanner to recognize the words i have for it

I’m pretty new to java and coding in general and am trying to figure out how to get this game to work for a project at school. It is meant for you to type in a month and it will then ask you to choose a day, however when I input a month it always just says its an invalid input, which is what I want it to do when it is not a valid month. What am I doing wrong?

import java.util.*;

class Main {
    public static void main(String[] args) {
        boolean game = true;
        do {
            System.out.println("Welcome to the Famous Date game!");
            System.out.println("Please choose a month");
            Scanner Month = new Scanner(System.in);
            String  Choice = Month.nextLine();
            String[] Months = {"January", "February", "March", "April", "May", "June","July",                    
"August","September","October","November", "December"};
            List<String> mylist = Arrays.asList(Months);
            if (Choice.equals(mylist)) {
                System.out.println("Please choose a day");
            }
            else
                System.out.println("That is not a valid month");
        }
        while (game=true);
    }
}

Advertisement

Answer

try to test if contains the month list.contains() and the days in an other methode just call it

Advertisement