在另一个void函数中传递私有void函数(编译错误java)

在另一个void函数中传递私有void函数(编译错误java),java,compilation,void,Java,Compilation,Void,假设我有一个函数,当输入一个参数时,它将名称转换为大写的第一个字母,其余的则转换为小写 我有另一个功能系统打印其他东西,包括我上面提到的功能。但我不断得到编译错误,说这里不允许使用'void'类型 Java还是很新的,我不知道如何调整它。有人能帮我一下吗 这是我提到的第一个函数 private void makePrettyString(String modelName) { // Change first letter of the name into upper c

假设我有一个函数,当输入一个参数时,它将名称转换为大写的第一个字母,其余的则转换为小写

我有另一个功能系统打印其他东西,包括我上面提到的功能。但我不断得到编译错误,说这里不允许使用'void'类型

Java还是很新的,我不知道如何调整它。有人能帮我一下吗

这是我提到的第一个函数

private void makePrettyString(String modelName)
    {

        // Change first letter of the name into upper case and store the first char only
        char first = Character.toUpperCase(modelName.charAt(0));

        // lower case the whole name
        String lower = modelName.toLowerCase();

        // store the whole name except the first char into the variable
        String restInLowerCase = lower.substring(1);

        // Combine the first char (which is upper case) and the rest of the name (which is in lower case)
        this.modelName = first+restInLowerCase; 
    }
第二个函数用于获取一些详细信息

public void getCarDetails()
{
    System.out.println(makePrettyString(modelName));
}
行-->
System.out.println(makePrettyString(modelName))
将导致错误,因为定义了
println()
的类
PrintStream
没有以
void
为参数的
println()
重载方法

检查所有重载的方法

只是想澄清一下,请注意,在Java中不能有一个接受
void
作为参数的方法。现在,
void
有一个占位符/包装器,名为
void
,它*还需要一个
void
类型的参数-->
System.out.println(makePrettyString(modelName))
将导致错误,因为定义了
println()
的类
PrintStream
没有以
void
为参数的
println()
重载方法

检查所有重载的方法

只是想澄清一下,请注意,在Java中不能有一个接受
void
作为参数的方法。现在,
void
有一个占位符/包装器,名为
void
,它*还需要一个
void
类型的参数-->
System.out.println(makePrettyString(modelName))
将导致错误,因为定义了
println()
的类
PrintStream
没有以
void
为参数的
println()
重载方法

检查所有重载的方法

只是想澄清一下,请注意,在Java中不能有一个接受
void
作为参数的方法。现在,
void
有一个占位符/包装器,名为
void
,它*还需要一个
void
类型的参数-->
System.out.println(makePrettyString(modelName))
将导致错误,因为定义了
println()
的类
PrintStream
没有以
void
为参数的
println()
重载方法

检查所有重载的方法


只是想澄清一下,请注意,在Java中不能有一个接受
void
作为参数的方法。现在,有一个名为
void
的占位符/包装器,如果
getCarDetails()
makePrettyString()
都在同一个类中,那么它*还需要一个
void
类型的参数

只需写
makePrettyString();
System.out.println(this.modelName)

您可以在
makePrettyString()
方法中访问
this.modelName
,而不是使用参数
makePrettyString(String modelName)


HTH.

如果两个方法
getCardDetails()
makePrettyString()
在同一个类中

只需写
makePrettyString();
System.out.println(this.modelName)

您可以在
makePrettyString()
方法中访问
this.modelName
,而不是使用参数
makePrettyString(String modelName)


HTH.

如果两个方法
getCardDetails()
makePrettyString()
在同一个类中

只需写
makePrettyString();
System.out.println(this.modelName)

您可以在
makePrettyString()
方法中访问
this.modelName
,而不是使用参数
makePrettyString(String modelName)


HTH.

如果两个方法
getCardDetails()
makePrettyString()
在同一个类中

只需写
makePrettyString();
System.out.println(this.modelName)

您可以在
makePrettyString()
方法中访问
this.modelName
,而不是使用参数
makePrettyString(String modelName)


嗯。

谢谢大家的帮助! 我刚刚意识到这就是我所需要做的,将方法从
void
更改为
String
,当然,正如每个人所说,返回一些东西 所以这是有效的

private String makePrettyString(String modelName)
{

    // Change first letter of the name into upper case and store the first char only
    char first = Character.toUpperCase(modelName.charAt(0));

    // lower case the whole name
    String lower = modelName.toLowerCase();

    // store the whole name except the first char into the variable
    String restInLowerCase = lower.substring(1);

    // Combine the first char (which is upper case) and the rest of the name (which is in lower case)
    return = first+restInLowerCase; 
}

谢谢大家的帮助! 我刚刚意识到这就是我所需要做的,将方法从
void
更改为
String
,当然,正如每个人所说,返回一些东西 所以这是有效的

private String makePrettyString(String modelName)
{

    // Change first letter of the name into upper case and store the first char only
    char first = Character.toUpperCase(modelName.charAt(0));

    // lower case the whole name
    String lower = modelName.toLowerCase();

    // store the whole name except the first char into the variable
    String restInLowerCase = lower.substring(1);

    // Combine the first char (which is upper case) and the rest of the name (which is in lower case)
    return = first+restInLowerCase; 
}

谢谢大家的帮助! 我刚刚意识到这就是我所需要做的,将方法从
void
更改为
String
,当然,正如每个人所说,返回一些东西 所以这是有效的

private String makePrettyString(String modelName)
{

    // Change first letter of the name into upper case and store the first char only
    char first = Character.toUpperCase(modelName.charAt(0));

    // lower case the whole name
    String lower = modelName.toLowerCase();

    // store the whole name except the first char into the variable
    String restInLowerCase = lower.substring(1);

    // Combine the first char (which is upper case) and the rest of the name (which is in lower case)
    return = first+restInLowerCase; 
}

谢谢大家的帮助! 我刚刚意识到这就是我所需要做的,将方法从
void
更改为
String
,当然,正如每个人所说,返回一些东西 所以这是有效的

private String makePrettyString(String modelName)
{

    // Change first letter of the name into upper case and store the first char only
    char first = Character.toUpperCase(modelName.charAt(0));

    // lower case the whole name
    String lower = modelName.toLowerCase();

    // store the whole name except the first char into the variable
    String restInLowerCase = lower.substring(1);

    // Combine the first char (which is upper case) and the rest of the name (which is in lower case)
    return = first+restInLowerCase; 
}

将函数修改为:

private String makePrettyString(String modelName) {

   //Your existing code

   return this.modelName;
}

通过以上操作,您的作业将被解析为System.out.println(有趣的调用)的udner参数,该参数预期的值与所写的值相同,但不幸的是,该值是无效的

将函数修改为:

private String makePrettyString(String modelName) {

   //Your existing code

   return this.modelName;
}

通过以上操作,您的作业将被解析为System.out.println(有趣的调用)的udner参数,该参数预期的值与所写的值相同,但不幸的是,该值是无效的

将函数修改为:

private String makePrettyString(String modelName) {

   //Your existing code

   return this.modelName;
}
通过上面的操作,您的作业将被解析为udner System.out.println(fun call)参数,该参数期望某个写入的值,该值不可格式化