> "); String binary = sc.nextLine(); // 2진수 문자열을 10진수로 변환 int decimal = Integer.parseInt(binary, 2); // 결과 출력 System.out.println(binary + "(2) = " + decimal + "(10)"); sc.close(); } } "> > "); String binary = sc.nextLine(); // 2진수 문자열을 10진수로 변환 int decimal = Integer.parseInt(binary, 2); // 결과 출력 System.out.println(binary + "(2) = " + decimal + "(10)"); sc.close(); } } "> > "); String binary = sc.nextLine(); // 2진수 문자열을 10진수로 변환 int decimal = Integer.parseInt(binary, 2); // 결과 출력 System.out.println(binary + "(2) = " + decimal + "(10)"); sc.close(); } } ">
import java.util.Scanner;
public class BinaryToDecimal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("===== 2진수를 10진수로 변환하기 =====");
System.out.print("2진수 입력>> ");
String binary = sc.nextLine();
// 2진수 문자열을 10진수로 변환
int decimal = Integer.parseInt(binary, 2);
// 결과 출력
System.out.println(binary + "(2) = " + decimal + "(10)");
sc.close();
}
}