我有这个源代码:(这是我的作业)。创建一个程序,将数字从十进制转换为二进制。我马上就好。
package binek;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Binek {
public static void main(String[] args) {
String cislo;
int vypocet=1;
int zbytek=1;
int a=0;
BufferedReader in;
in = new BufferedReader(new InputStreamReader(System.in));
try{ cislo = in.readLine(); }
catch(IOException e) {cislo="";}
int dec=Integer.valueOf(cislo);
int[] pole = new int[10];
vypocet=dec/2;
zbytek=dec%2;
pole[0]=zbytek;
while(vypocet!=0){
a++;
zbytek=vypocet%2;
vypocet=vypocet/2;
pole[a]=zbytek;
}
for (int i = 9; i < pole.length; --i)
{
System.out.print (pole[i]);
} // here is the field with unnecessary zeros
}
}