How to check whether given string is a word

前端 未结 6 1085
礼貌的吻别
礼貌的吻别 2020-12-02 00:51

Hello I am developing a word game where i want to check the user input as valid word or not please suggest the way i can check the given string in android.

Eg . Str

6条回答
  •  一整个雨季
    2020-12-02 01:18

    You can try this code for basic validation

    import java.util.Scanner;
    
    public class InputValidation {
    
        public static void main(String[] args) {
            String input;
            try {
                System.out.println("Enter the input");
                Scanner s = new  Scanner(System.in);
    
                input = s.next();
                if(input.matches(".*\\d.*")){
                    System.out.println(" Contains digit only");
                } else{
                    System.out.println(" Only String/words found");
                }
    
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
    
        }
    
    }
    

提交回复
热议问题