import javax.swing.*;
class compute
{
long square(long x)
{
return x*x;
}
boolean[] binary(long x)
{
int bitN=(int)Math.ceil(Math.log(x+1)/Math.log(2));
boolean [] b=new boolean[bitN];
int i=bitN-1;
do
{
b[i--]=((x&1)==1)?true:false;
x=x>>1;
} while (x!=0);
for (i=0;i<bitN; i++)
System.out.print(b[i]?1:0);
System.out.println();
return b;
}
}
public class power
{
public static void main(String[] argv) throws Exception
{
compute math=new compute();
long x=new Long(JOptionPane.
showInputDialog("x=")).longValue();
boolean[] b=math.binary(x);
long y=math.square(x);
JOptionPane.showMessageDialog(null, x+"*"+x+"="+Long.toString(y));
}
}
沒有留言:
不接受新意見。