【2017年整理】JAVA二进制转换为十进制

上传人:豆浆 文档编号:990257 上传时间:2017-05-24 格式:DOCX 页数:2 大小:14.90KB
返回 下载 相关 举报
【2017年整理】JAVA二进制转换为十进制_第1页
第1页 / 共2页
【2017年整理】JAVA二进制转换为十进制_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《【2017年整理】JAVA二进制转换为十进制》由会员分享,可在线阅读,更多相关《【2017年整理】JAVA二进制转换为十进制(2页珍藏版)》请在金锄头文库上搜索。

1、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

2、&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);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号