算法訓練 判定數字
時間限制:1.0s 記憶體限制:512.0MB
編寫函數,判斷某個給定字元是否為數字。
樣例輸入
9
樣例輸出
yes
import java.util.Scanner;
public class 判定數字 {
public static void main(String[] args) throws Exception {
Scanner scanner=new Scanner(System.in);
String str=scanner.nextLine();
boolean flag=isNumber(str);
if(flag){
System.out.println("yes");
} else {
System.out.println("no");
}
}
private static boolean isNumber(String str){
for(int i=0;i<str.length();i++){
if(str.charAt(i)<'0' || str.charAt(i)>'9'){
return false;
}
}
return true;
}
}