嗯。这很尴尬,但我得到一些错误,说的是完全不真实的东西。
有人可以给我一个关于如何修复它的建议。我是java的新手,所以简单的答案是最好的。
感谢。
public class Project1
{
public static void main( String [] args )
{
System.out.println();
String output = new String();
String inital = new String();
inital = english_to_morse();
for( int k = 0; k < inital.length(); k++)
{
output += morse(inital.charAt( k ));
}
System.out.print(output);
System.out.println();
}
public static void choice()
{
int user_choice = 0; ///This is the method giving me grief!!!!!!
user_choice = Input.getInt("Enter 1 if you want to change English to Morse code, and enter 2 to change Morse code to English");
if(user_choice == 1)
{
english_to_morse();
}
if(user_choice == 2)
{
morse_to_english();
}
public static String english_to_morse()
{
String user_input = new String();
user_input = Input.getString("Enter a phrase and I'll convert it to Morse Code");
return user_input.toLowerCase();
}
public static String morse_to_english()
{
String user_input = new String();
user_input = Input.getString("Enter a phrase in Morse Code and I'll convert it to English");
return user_input.toLowerCase();
}
public static String morse(char letter)
{
String output = new String();
char[] alphabet_numbers = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ' };
String morse_code[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "|" };
for( int j = 0; j < alphabet_numbers.length; j++ )
{
if (alphabet_numbers[j]==letter)
{
output = morse_code[j];
}
}
return output + " ";
}
}
答案 0 :(得分:5)
这是问题所在:
public static void choice()
{
int user_choice = 0; ///This is the method giving me grief!!!!!!
user_choice = Input.getInt("Enter 1 if you want to change English to Morse code, and enter 2 to change Morse code to English");
if(user_choice == 1)
{
english_to_morse();
}
if(user_choice == 2)
{
morse_to_english();
}
public static String english_to_morse()
您永远不会完成choice()
方法 - 因此您无法启动english_to_morse
方法。
我强烈怀疑编译器的第一条错误消息是在english_to_morse
方法的开头。一旦你的源被破坏(试图在另一个内部声明一个方法),其他错误消息可能看起来很奇怪就不足为奇了。
这是一个好主意: