[英]Errors that don't exist
Umm. 嗯。 This is awkward but I'm getting some errors that say stuff that is totally untrue.
这很尴尬,但我遇到了一些错误,这些错误说的是完全不真实的内容。
Could someone give me a suggestion on how to fix it. 有人可以给我建议如何解决它。 I'm new to java so simple answers would be the best.
我是Java新手,所以简单的答案将是最好的。
Thanks. 谢谢。
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 + " ";
}
}
This is the problem: 这就是问题:
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()
You never finish the choice()
method - so you can't start the english_to_morse
method. 您永远不会完成
choice()
方法,因此无法启动english_to_morse
方法。
I strongly suspect that the first error message from the compiler was at the start of the english_to_morse
method. 我强烈怀疑来自编译器的第一条错误消息是在
english_to_morse
方法的开头。 Once you're source is that broken (trying to declare one method inside another) it shouldn't be a surprise that other error messages may seem strange. 一旦您发现问题已损坏(试图在另一个方法中声明一个方法),其他错误消息似乎很奇怪也就不足为奇了。
It's a good idea to: 这是一个好主意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.