오늘 새벽에 풀었던 1152번을 조금만 응용하면 풀 수 있는 문제였습니다. 먼저 값을 입력받고 모두 곱해준 값을 스트링형으로 저장을 합니다. charAt로 String형 배열에 값들을 저장하고 0~10을 비교해 맞는 값이 있으면 1씩 더해줍니다.
if 쓸 때 int는 == String은 .equals("")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
String[] result = new String[10]; | |
int[] result2 = new int[10]; | |
Scanner sc = new Scanner(System.in); | |
int a = sc.nextInt(); | |
int b = sc.nextInt(); | |
int c = sc.nextInt(); | |
sc.close(); | |
int mul = a*b*c; | |
String exp = String.valueOf(mul); | |
for(int i=0; i<exp.length(); i++) { | |
result[i] = String.valueOf(exp.charAt(i)); | |
for(int j=0; j<10; j++) { | |
String js = String.valueOf(j); | |
if(result[i].equals(js)) { | |
int js2=Integer.parseInt(js); | |
result2[js2] =result2[js2]+1; | |
} | |
} | |
} | |
for(int i=0; i<10; i++) { | |
System.out.println(result2[i]); | |
} | |
} | |
} |
'백준 알고리즘 > JAVA' 카테고리의 다른 글
[JAVA 자바] 백준 2920번 음계 (0) | 2018.07.09 |
---|---|
[JAVA 자바] 백준 8958번 OX퀴즈 (0) | 2018.07.09 |
[JAVA 자바]백준 1110번 (0) | 2018.07.07 |
[JAVA 자바] 백준 4344번 (0) | 2018.07.06 |
[JAVA 자바] 백준 1546번 (0) | 2018.07.05 |