【发布时间】:2016-02-22 04:52:42
【问题描述】:
我的任务是:编写一个应用程序,打印一个十进制数的二进制、八进制和十六进制等值表 在 1 到 256 的范围内。如果您不熟悉这些数字系统,请在线研究所需信息 将结果放在 JOptionPane.showMesaageDialog 中。
我目前的代码是:
import javax.swing.*;
public class Prog3_22
{
public static void main (String args[])
{
int a;
int b;
int c;
String billybob = "Decimal "+"\tBinary"+"\tOctal "+"\tHex",binary,oct,hex;
for(int x=1;x<=256;x++)
{
binary="";oct="";hex="";
c=x;
a=x;
b=x;
while (c>0)
{
int rem= c %2;
binary=rem+binary;
c=c/2;
}//end while
while (b>0)
{
int rem= h%16;
hex=rem+hex;
b=b/16;
}
while (a>0)
{
int rem= a%8;
oct=rem+oct;
a=a/8;
}
billybob+="\n" +x+ "\t"+binary+"\t"+oct+"\t"+hex+"\t";
}//end for
JTextArea outputArea = new JTextArea (10,40);
JScrollPane scroller = new JScrollPane (outputArea);
outputArea.setText(billybob);
JOptionPane.showMessageDialog(null,scroller,null,
JOptionPane.INFORMATION_MESSAGE);
}
}
除了显示为 0 的 Hex 列之外,它大部分都有效。我不知道如何修复它,所以任何帮助都会很棒。
谢谢!
【问题讨论】:
-
我们可以看看输出的样本吗?
-
不知道怎么把这一切都放进去,抱歉。 docs.google.com/document/d/…