java - 如何调用字符串类型的方法?
问题描述
如何在main方法中调用这个方法?我无法在主方法中调用我的用户定义方法。怎么做?
public class Concat {
public static void main(String[] args) {
}
public static String UserInfo (String name, String email, String address) {
name="vgfhk";
email="dbdkjb";
address="jbkug";
String code="Thanks for running the code\n\n";
String below="Your information is given below:\n";
String thanksMsg = "Hello, "+name+code+below;
String userInformation="Name: "+name+"email: "+email+"Address: "+address;
return thanksMsg.concat(userInformation);
}
}
解决方案
您可以简单地调用已将其定义为静态的函数。我已将输入值作为 Null 传递,您可以根据需要进行替换。
public class Concat {
public static void main(String[] args) {
String result = userInfo(null, null, null);
}
public static String userInfo (String name, String email, String address) {
name="Farhan";
email="dbdkjb";
address="mirpur";
String code="Thanks for running the code\n\n";
String below="Your information is given below:\n";
String thanksMsg = "Hello, "+name+code+below;
String userInformation="Name: "+name+"email: "+email+"Address: "+address;
return thanksMsg.concat(userInformation);
}
}
注意 :您的方法名称不遵循 java 编码约定。您应该遵循有关它的 Oracle 指南。https://www.oracle.com/technetwork/java/codeconventions-135099.html
推荐阅读
- python - 导入后任意修改导入一个python模块
- html - 使用角度 ng-repeat 从对象动态创建 HTML 表格行
- python - 函数中样条和多条线之间的交点
- python - 递归字符串替换
- python - Django 应用程序无法识别 .env 文件,我尝试通过 os、Django-environ 和 dotenv 进行设置,但没有任何效果
- django - Django 表单中的 Queryset 对象不可迭代
- c# - 为什么 GetProcesses() 不显示所有正在运行的进程
- python-3.x - python3:无法打开文件 - 如何使用 Docker 访问目录
- r - 如何从 R 中的文本文件中读取?
- python - 如果满足条件,则使用另一列中的多个字符串之一更改一列