[Java练手] - HDU2024

回头看,当时好像是为了练手写Java,刷题

import java.util.*; public class Main { //http://acm.hdu.edu.cn/showproblem.php?pid=2024 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cnt = sc.nextInt(); WordCheck wc = new WordCheck(); String str = sc.nextLine(); for(int i=0; i<cnt; ++i){ str = sc.nextLine(); if(wc.isOk(str)){ System.out.println("yes"); }else{ System.out.println("no"); } } } } class WordCheck{ public WordCheck(){} boolean isNumber(char c){ if(c >= '0' && c <= '9') return true; return false; } boolean isAlpha(char c){ if(c >= 'A' && c <= 'z') return true; return false; } boolean isUnderline(char c){ if(c == '_') return true; return false; } boolean isOk(String str){ if(!(isUnderline(str.charAt(0)) || isAlpha(str.charAt(0)))){ return false; } for(int i=1; i<str.length(); ++i){ if(!(isUnderline(str.charAt(i)) || isAlpha(str.charAt(i)) || isNumber(str.charAt(i)))) return false; } return true; } }

你可能感兴趣的:(java,c,String,Class,import)