Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static boolean CheckStrType(String str) {
        boolean check = true;
        for (int i = 0; i < str.length(); i++) {
            String tmp = str.substring(i, i + 1);
            if (isChinese(tmp)) {
                check = true;
            } else if (isEnglish(tmp)) {
                check = true;
            } else {
                return false;
            }
        }
        return check;
    }

    public static boolean isChinese(String name) {
        int j = 0;
        int i = name.length();
        Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]");
        Matcher m = pattern.matcher(name);
        while (m.find()) {
            j++;
        }
        if (i == j) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isEnglish(String english) {
        Pattern pattern = Pattern.compile("^[A-Za-z]+$");
        Matcher m = pattern.matcher(english);
        if (m.matches()) {
            return true;
        } else {
            return false;
        }
    }
}