> "); String numbers = sc.nextLine(); int dashCount = countDashes(numbers); System.out.println("대시('-')의 총 합 >> " + dashCount); sc.close(); } public static int countDashes(String number) { int total = 0; for(char digit : number.toCharArray()) { switch(digit) { case '1': total += 2; break; // 1은 2개의 대시 case '2': total += 5; break; // 2는 5개의 대시 case '3': total += 5; break; // 3은 5개의 대시 case '4': total += 4; break; // 4는 4개의 대시 case '5': total += 5; break; // 5는 5개의 대시 case '6': total += 6; break; // 6은 6개의 대시 case '7': total += 3; break; // 7은 3개의 대시 case '8'"> > "); String numbers = sc.nextLine(); int dashCount = countDashes(numbers); System.out.println("대시('-')의 총 합 >> " + dashCount); sc.close(); } public static int countDashes(String number) { int total = 0; for(char digit : number.toCharArray()) { switch(digit) { case '1': total += 2; break; // 1은 2개의 대시 case '2': total += 5; break; // 2는 5개의 대시 case '3': total += 5; break; // 3은 5개의 대시 case '4': total += 4; break; // 4는 4개의 대시 case '5': total += 5; break; // 5는 5개의 대시 case '6': total += 6; break; // 6은 6개의 대시 case '7': total += 3; break; // 7은 3개의 대시 case '8'"> > "); String numbers = sc.nextLine(); int dashCount = countDashes(numbers); System.out.println("대시('-')의 총 합 >> " + dashCount); sc.close(); } public static int countDashes(String number) { int total = 0; for(char digit : number.toCharArray()) { switch(digit) { case '1': total += 2; break; // 1은 2개의 대시 case '2': total += 5; break; // 2는 5개의 대시 case '3': total += 5; break; // 3은 5개의 대시 case '4': total += 4; break; // 4는 4개의 대시 case '5': total += 5; break; // 5는 5개의 대시 case '6': total += 6; break; // 6은 6개의 대시 case '7': total += 3; break; // 7은 3개의 대시 case '8'">
import java.util.Scanner;
public class DashCounter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("첫자리 0을 제외한 숫자를 입력해주세요 >> ");
String numbers = sc.nextLine();
int dashCount = countDashes(numbers);
System.out.println("대시('-')의 총 합 >> " + dashCount);
sc.close();
}
public static int countDashes(String number) {
int total = 0;
for(char digit : number.toCharArray()) {
switch(digit) {
case '1': total += 2; break; // 1은 2개의 대시
case '2': total += 5; break; // 2는 5개의 대시
case '3': total += 5; break; // 3은 5개의 대시
case '4': total += 4; break; // 4는 4개의 대시
case '5': total += 5; break; // 5는 5개의 대시
case '6': total += 6; break; // 6은 6개의 대시
case '7': total += 3; break; // 7은 3개의 대시
case '8': total += 7; break; // 8은 7개의 대시
case '9': total += 6; break; // 9는 6개의 대시
case '0': total += 6; break; // 0은 6개의 대시
}
}
return total;
}
}