本人初学java 请教一个简单问题
import java.io.*;
class buma
{
private static int getaninput(InputStream in)
{
try
{ int i=in.read();
return (i);
}
catch (
IOException e)
{
System.out.println(e);
}
}
public static void main(String[] args)
{ System.out.println("input the requested number:");
int input=getaninput(System.in);
int n,i=0;
int m=input;
int a[]=new int[20];
while(m!=0)
{n=m%2;
a[i++]=n;
m=m/2;
}
for(int t=i-1;t>=0;t--)
System.out.print(a[t]);
}
}
这是一个求正数补码的程序,有问题,请帮忙看一下,谢谢!!!!
------解决方案--------------------有一些小错误
import java.io.*;
class buma {
private static int getaninput(InputStream in) {
int i = 0;
try {
i = in.read();
}
catch (IOException e) {
System.out.println(e);
}
return i;
}
public static void main(String[] args) {
System.out.println("input the requested number:");
int input = getaninput(System.in);
int n, i = 0;
int m = input;
int a[] = new int[20];
while(m != 0 ) {
n = m % 2;
a[i++] = n;
m = m / 2;
}
for(int t = i-1; t >= 0; t--)
System.out.print(a[t]);
}
}