package com.yue.www;
import java.util.Scanner;
public class De10zhuan2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入一个10进制数字");
Scanner sc =new Scanner(System.in);
int a=sc.nextInt();
System.out.println("a="+a);
toBin(a);
}
public static void toBin(int num){
System.out.print("num="+num);
StringBuffer sb=new StringBuffer();
while(num>0);{
sb.append(num%2);//想数组添加元素
num = num / 2;
}
System.out.print(sb.reverse());//数组反向输出
}
}
|
-
HHHH.jpg
(27.98 KB, 下载次数: 0)
运行结果 这是哪出错了
|