使用 switch case 将字母(AF 和任何其他应该说错误)转换为二进制,这是主要的:
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();”期间找不到符号 不确定是什么问题