我在製作文件時遇到了麻煩,我想我已經獲得了大部分的正確性,但是我遇到了getMorseCode()方法的問題。我幾乎可以肯定它始於Java:字符串,字符,如果,錯誤
String morse = "";
然而,因爲字母是char和莫爾斯是一個字符串,它導致錯誤。否則,它符合,但只是返回一個空格,當我運行測試器時,我不知道該在引號中加什麼引號,任何人都可以給我一個提示嗎?
感謝,
public class MorseCode
{
private char letter;
public MorseCode(char let)
{
letter = let;
}
public char getLetter()
{
return letter;
}
public String getMorseCode()
{
String morse = "";
if (morse.equalsIgnoreCase("a"))
morse = ".-";
return morse;
}
}
import java.util.Scanner;
/**
* A class to test the MorseCode class
*/
public class MorseCodeTester
{
/**
* Tests methods of the MorseCode class
* @param args not used
*/
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a character: ");
char morseChar = input.nextLine().charAt(0);
MorseCode one = new MorseCode(morseChar);
System.out.println(one.getLetter() + " is " + one.getMorseCode() + " in morse!\n");
我刪除了我的答案,因爲我輸入的速度比我想象的要快。我注意到那封信是一個炭太晚:) – Dave
哈哈,它發生在我們最好的:p。 – Zhanger
謝謝,它的話 –