展开全部
import java.util.Scanner; public class S_T { public static void main(String[] args) { int x=0,y=0; Scanner scanner = new Scanner(System.in); try { x = scanner.nextInt(); }catch(java.util.InputMismatchException ime) { //if the next token does not match the Integer regular //expression, or is out of range System.out.println("not a integer"); } System.out.println("输入的二进制数是:"+x); int n=0,t=1; while(x>0) { y+=x%10*t; x=x/10; n++; t=t*2; } System.out.print("输出的十进制数是:"+y); } } 要转化的二进制数在控制台中输入..
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询