资源预览内容
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
import java.util.Scanner;public class binaryToDecimal /* param args*/public static int binary(String str)/Scanner input=new Scanner(System.in);/System.out.print(Please input your string:);/String str=input.next();int len=str.length();char ch;int num=0;for(int i=len-1;i=0;i-)ch=str.charAt(i);if(ch!=0&ch!=1)System.out.println(input wrong!);break;if(ch=1)num= (int) (num+Math.pow(2,(len-1)-i);return num;public static void main(String args) / TODO Auto-generated method stubScanner input=new Scanner(System.in);while(true)System.out.print(Please input your string:);String str=input.next();int total;total=binary(str);System.out.println(total=+total);
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号