GUIを使用して2進数を10進数に変換するプログラムを作成する必要があります。まず、GUIを使わずにプログラムを作ったところ、うまくいきました。私はGUIと試み、プログラムをしながら私は、任意の入力を大幅に理解される私はプリミティブ型intでlength()を呼び出せません
int BinaryNumber, DecimalNumber;
try {
BinaryNumber = Integer.parseInt(textFieldtUserBinaryInput.getText());
DecimalNumber = 0;
for (int i = 0; i < BinaryNumber.length(); i++);
{
Character binary = BinaryNumber.charAt(i);
String temp = binary.toString();
int tempInt = Integer.parseInt(temp);
DecimalNumber = DecimalNumber * 2 + tempInt;
textFieldDecimal.setText(Integer.toString(DecimalNumber));
}
}catch (NumberFormatException exp){
JOptionPane.showMessageDialog(null, "Invalid format for a binary string - Illegal character");
}
}
「プリミティブ型intに()長さを呼び出すことはできません」というエラーメッセージを取得し続けます。ありがとう!
これは、私はそれがGUIに
public static int ConvertToDecimal(String BinaryNumber)
{
String pattern = "[0-1]*";
boolean patternMatched = Pattern.matches(pattern, BinaryNumber);
if(patternMatched)
{
int Decimal = 0;
for (int d = 0; d < BinaryNumber.length(); d++)
{
Character binary = BinaryNumber.charAt(d);
String temp = binary.toString();
int tempInt = Integer.parseInt(temp);
Decimal = Decimal * 2 + tempInt;
}
return Decimal;
}
エラーはかなりわかりやすく、GUIとは何の関係もありません。あなたには何が分かりませんか? – shmosel
私はその関数でBinaryNumberをどのように動作させるか分かりません。私がプログラムを正常に実行したときには、 (int d = 0; d