티스토리 뷰

public class ConfirmNum {


static boolean isNumber(String str) {


if (str == null)

return false;


for (int i = 0; i < str.length(); i++) {

if (str.charAt(i) == ' ') {

// return false;

System.out.println(str.charAt(i));

return false;

} else if (str.charAt(i) < 48 || str.charAt(i) > 58)

return false;

}

return true;

}


public static void main(String[] args) {

// TODO Auto-generated method stub

String str = "123";

System.out.println(str + "는 숫자인가? " + isNumber(str));


str = "1234o";

System.out.println(str + "는 숫자인가? " + isNumber(str));


}

}





댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함