Java 字符到字符串协助

Java 字符到字符串协助,java,Java,我得到的错误在第35行,它说“类Project1中的方法英语不能应用于给定的类型。我不理解,任何帮助都将不胜感激。我认为我需要切换变量类型,但我不知道如何切换。顺便说一句,我是java新手,正在尝试尽快学习 public class Project1 { public static void main( String [] args ) { System.out.println(); choice(); } public static void choice() {

我得到的错误在第35行,它说“类Project1中的方法英语不能应用于给定的类型。我不理解,任何帮助都将不胜感激。我认为我需要切换变量类型,但我不知道如何切换。顺便说一句,我是java新手,正在尝试尽快学习

public class Project1
{
public static void main( String [] args )
{
    System.out.println();
    choice();

}
    public static void choice()
{
    int user_choice = 0; 
    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)
    {
    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);

    }
    if(user_choice == 2)
    {
    String output2 = new String();
    String inital2 = new String();
    inital2 = english_to_morse();

    for( int k = 0; k < inital2.length(); k++)
    {
        output2 += english(inital2.charAt( k ));///the error is here
    }

        System.out.print(output2);
    }
}

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 + " ";
}   
public static String english(String letter)
{
    String output = new String();
    String 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 < morse_code.length; j++ )
    {
        if (morse_code[j]==letter)
        {
            output = alphabet_numbers[j];
        }
    }
    return output + " ";
}   
公共类项目1
{
公共静态void main(字符串[]args)
{
System.out.println();
选择();
}
公共静态无效选择()
{
int user_choice=0;
user_choice=Input.getInt(“如果要将英语更改为摩尔斯电码,请输入1,如果要将摩尔斯电码更改为英语,请输入2”);
如果(用户选择==1)
{
字符串输出=新字符串();
String inital=新字符串();
inital=英语从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句从句;
对于(int k=0;k

}

您不能直接将
char
转换为字符串。为此,请使用
String.valueOf()

在这一行中,您的方法
english()
接受
String
作为参数,但您将
char
传递给它

output2 += english(inital2.charAt( k ));
但它应该是:

output2 += english(String.valueOf(inital2.charAt( k )));

english
方法将字符串作为参数。调用
output+=english(inital.charAt(k));
尝试将字符作为输入。您可能希望使用
inital.substring(k,k+1)
而不是
inital.charAt(k)
提供一个单字符字符串作为参数,而不是一个字符。

注意:我们不知道第35行是什么。如果将来可以,请复制/粘贴错误消息,并指出导致问题的行,这将非常有用。另外,请查看
公共静态字符串英文(字符串字母)的签名
以及调用它的参数。另请参见将传递到方法中的变量类型与该方法在其声明中预期的变量类型进行比较。它们需要匹配;该错误表示它们不匹配。我用comment@user3474526请看英文方法的签名以及参数rs您可以调用它。@user3474526我们每个人都是:-)您可能需要对代码进行一点跟踪,以确保所有函数都正确执行。