使用切换大小写将字母(A-F和任何其他字母应表示错误)转换为二进制
这是主要的:

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a letter :: ");
String letter = keyboard.next();
keyboard.getBinary();
keyboard.toString();


和班级:

import static java.lang.System.*;
public class HexToBinary
{
private char hex;

public HexToBinary()
{
    hex=0;
}

public HexToBinary(char hexNum)
{

    hex=hexNum;
}

public void setHex(char hexNum)
{
    hex=hexNum;
}

public String getBinary()
{
    String letter = letter;
    switch(letter)
    {
        case A: letter = 1010;
        case B: letter = 1011;
        case C: letter = 1100;
        case D: letter = 1101;
        case E: letter = 1110;
        case F: letter = 1111;
        case default: letter = ERROR;
    }
    return "";
}

public String toString()
{
    System.out.println(letter+" is " getBinary + "in binary!")
    return "";
}


该错误表明它在“ keyboard.getBinary();”期间找不到符号
不确定是什么问题

最佳答案

该错误表明它在“ keyboard.getBinary();”期间找不到符号不确定是什么问题


扫描程序没有getBinary()方法,因为API会告诉您:Scanner API

更重要的是
但是您的HexToBinary类确​​实具有此方法。您将要创建一个HexToBinary变量,为其分配一个HexToBinary对象,然后在此变量上调用此方法。

所以不是:

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a letter :: ");
String letter = keyboard.next();
keyboard.getBinary();
keyboard.toString();


反而:

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a letter :: ");
String letter = keyboard.next();

// check that letter has only one char in it.
// convert your letter to a char.
// create a HexToBinary variable and object here
// use its methods to convert the char to binary.

10-04 20:24