자바 isInteger()

1 개요[ | ]

자바 isInteger()
  • 여기서는 String형을 정수인지 검사하는 것을 구현한다.
public class MyClass {
	public static boolean isInteger(String input) {
		try {
			Integer.parseInt(input);
			return true;
		}
		catch (NumberFormatException e) {
			return false;
		}
	}
	public static void main(String args[]) {
		System.out.println( isInteger("42") ); // true
		System.out.println( isInteger("-1") ); // true

		System.out.println( isInteger("-1.0") ); // false
		System.out.println( isInteger("3.14") ); // false
	}
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}