Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ora-01722
- Oracle 18c HR schema
- ORA-12899
- Oracle 사용자명
- 윈도우 Oracle
- 오라클 캐릭터셋 확인
- Oracle 테이블 띄어쓰기
- 무료 오라클 데이터베이스
- Oracle Express Edition
- Oracle 사용자명 입력
- Oracle 초기 사용자
- 무료 오라클 설치
- Oracle 18c 설치
- 오라클 캐릭터셋 조회
- Oracle 테이블 대소문자
- 서평단
- Oracle 18c HR
- oracle 18c
- ORA-00922
- 오라클 캐릭터셋 변경
- oracle
- 비전공자를 위한 데이터베이스 입문
- Orace 18c
- Oracle 윈도우 설치
Archives
- Today
- Total
Nirsa's Learning Lab
[백준] 2577번: 숫자의 개수 (JAVA, 자바) 본문
반응형
2577번: 숫자의 개수 (JAVA, 자바)
이번 문제는 어쩌다보니 완전히 하드코딩으로 풀어 버렸습니다....
이게 맞나 싶은 코드지만 우연히 알게된 chars, filter, count로 해보니 덜컥 되어 버렸습니다. chars()는 String의 문자들을 스트림으로 만들어 주고, 필터를 통해 문자 '0'을 새로운 배열로 반환 후 count를 통해 개수를 새어 줍니다.
이렇게 0~9를 반복하여 하나씩 출력하면 String 문자열의 문자를 하나하나 확인 후 카운팅할 수 있습니다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum = (sc.nextInt() * sc.nextInt() * sc.nextInt());
String stringSum = Integer.toString(sum);
System.out.println(stringSum.chars().filter(ch -> ch == '0').count());
System.out.println(stringSum.chars().filter(ch -> ch == '1').count());
System.out.println(stringSum.chars().filter(ch -> ch == '2').count());
System.out.println(stringSum.chars().filter(ch -> ch == '3').count());
System.out.println(stringSum.chars().filter(ch -> ch == '4').count());
System.out.println(stringSum.chars().filter(ch -> ch == '5').count());
System.out.println(stringSum.chars().filter(ch -> ch == '6').count());
System.out.println(stringSum.chars().filter(ch -> ch == '7').count());
System.out.println(stringSum.chars().filter(ch -> ch == '8').count());
System.out.println(stringSum.chars().filter(ch -> ch == '9').count());
}
}
반응형
'코딩 테스트 > 백준' 카테고리의 다른 글
[백준] 8958번: OX퀴즈 (JAVA, 자바) (1) | 2022.03.19 |
---|---|
[백준] 1546번: 평균 (JAVA, 자바) (0) | 2022.03.19 |
[백준] 2562번: 최댓값 (JAVA, 자바) (0) | 2022.03.15 |
[백준] 10818번: 최소, 최대 (JAVA, 자바) (0) | 2022.03.15 |
[백준] 알고리즘 단계별로 풀어보기 - 3 (자바) (0) | 2022.03.09 |