본문 바로가기
TechKnowledge/알고리즘

항해 알고리즘 2일차

by 김코딩개발자 2022. 5. 14.

public class SimpleTesting {

    public static void main(String[] args) {
        String str = "123";
        boolean isNumeric =  str.matches("[+-]?\\d*(\\.\\d+)?");
        System.out.println(isNumeric);
        str = "121xy";
        isNumeric =  str.matches("[+-]?\\d*(\\.\\d+)?");
        System.out.println(isNumeric);
        str = "0x234";
        isNumeric =  str.matches("[+-]?\\d*(\\.\\d+)?");
        System.out.println(isNumeric);
    }
}

출력:

true
false
false

문자열이 숫자인지 판별하는 메소드  isNumeric
이것을 이용해하여 문제17번을 풀었다

============================================================================

  • 클래스와 인스턴스 메소드

시작에

class 클래스명){

데이터명 메소드 이름(데이터명 변수, 데이터명,변수){     매소드 내용 ex) x+y  }

}

이렇게 시작이된다

 

  • 생성자

public + 생성자명