Light Blue Pointer
본문 바로가기
개발일지

2023-11-20, Today I Learned

by 개발바닥곰발바닥!!! 2023. 11. 20.

오늘 배운 것

제곱근이 존재하는지 아닌지 원래 for문 돌려서 했는데 오늘 문득 sqrt를 쓰면 더 나을 거 같았음

 

⭐Java 제곱근 sqaure root

Math.sqrt(25);

Math.sqrt() 메소드는 입력값과 출력값은 모두 double형이며 Math.sqrt(대상숫자)를 넣어주면 됩니다.

 

 

⭐Java 정수부 소수부 분리 

  	double d = 123.456789555;

    // 소수의 정수부만 추출
    int ip = (int) d;

    // 소수의 소수부만 추출
    double fp = d - (int) d;
    // 출력 결과: 0.4567895550000003

💡소수부 == 0.0이면 제곱근 약수가 있는 수

 

⭐Java String to char Array

char[] chars = str.toCharArray();

 

⭐Java char array to String

String string = new String(charArray);

 

 

Java arrays.sort revers Order

import java.util.Arrays;
import java.util.Collections;

Arrays.sort(arr, Collections.reverseOrder());

 

Java Integer to int

Integer any = (Integer)ht.get("test");
int i = any.intValue();

 

⭐String match()

String이 특정 패턴의 문자열을 포함하는지 확인할 수 있음

문자열에 정규표현식(regex)이 일치하는지를 boolean으로 리턴

 

Regular Expression(Regex) Patterns

[abc] Find one character from the options between the brackets

[^abc] Find one character NOT between the brackets

[0-9] Find one character from the range 0 to 9

Metacharacters : characters with a special meaning

[ | ] Find a match for any one of the patterns separated by  as in: cat|dog|fish 

[ . ] Find just one instance of any character 

[ ^ ] Finds a match as the beginning of a string as in: ^Hello 

[ $ ] Finds a match at the end of the string as in: World$ 

[ \d ] Find a digit

[ \s ] Find a whitespace character

[ \b ] Find a match at the beginning of a word like this: \bWORD, or at the end of a word like this: WORD\b

[ \uxxxx ] Find the Unicode character specified by the hexadecimal number xxxx 

Quantifiers : Quantifiers define quantities

n+  Matches any string that contains at least one n
n* Matches any string that contains zero or more occurrences of n
n? Matches any string that contains zero or one occurrences of n
n{x} Matches any string that contains a sequence of X n's
n{x,y} Matches any string that contains a sequence of X to Y n's
n{x,} Matches any string that contains a sequence of at least X n's

 

 

⭐한 글자 String matches로 비교

s.matches("[0-9]")

 

⭐여러 글자 String matches로 비교

s.matches("(^[0-9]*$)")

'개발일지' 카테고리의 다른 글

2023-11-22, Today I Learned  (0) 2023.11.22
2023-11-21, Today I Leanred  (0) 2023.11.21
2023-11-17, Today I Learned  (0) 2023.11.17
2023-11-16, Today I Learned  (0) 2023.11.16
2023-11-09, Today I Learned  (0) 2023.11.09