英文:
Problem of printing ABC... and a number in Java
问题
这是我设置的函数:
public int printABCNum(int p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue += textinfo;
textinfo++;
}
System.out.println(textValue + Integer.toString(p));
}
Eclipse(一个文本编辑器)表示public int printABCNum(p)
这部分有问题。基本上我尝试的是运行一个打印"ABCDEFGHIJKLMNOPQRSTUVWXYZ"和一个整数的函数。我对Java还不太熟悉,对于使用它进行编程和查找错误不够有把握,所以请帮忙检查一下!
英文:
This is the function I set:
public int printABCNum(p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue+=textinfo;
textinfo++;
}
System.out.println(textValue + Integer.toString(p));
Eclipse (a text editor) says that there is a problem with public int printABCNum(p)
bit. Basically I'm trying to do is run a function printing "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and an integer. I'm new to Java and is not good 'enough' at programming with it and finding bugs, so please help!
答案1
得分: 2
一个 printABCNum
函数的 p
参数缺少类型说明。根据上下文,它应该是一个 int
类型。另一个问题是你的函数返回类型被定义为 int
,但是你并没有返回任何值。
你的代码应该是:
public void printABCNum(int p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue += textinfo;
textinfo++;
}
System.out.println(textValue + p);
}
英文:
A p
parameter of your printABCNum
function is missing a type. Based on context it should be an int
. Another problem is your function return type is defined to int
, but you haven't returned any value.
Your code should be:
public void printABCNum(int p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue += textinfo;
textinfo++;
}
System.out.println(textValue + p);
}
答案2
得分: 1
看起来有一些问题。
- 如果你不打算返回任何东西,就不应该有返回类型
int
。 - 参数需要有类型,像这样:
int p
除此之外看起来还不错。在下面看一下对我有用的完整答案。
public void printABCNum(int p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue += textinfo;
textinfo++;
}
System.out.println(textValue + Integer.toString(p));
}
英文:
It looks like there's a few things wrong here.
- You shouldn't have a return type
int
if you are not returning anything. - The parameter needs to have a type, as such:
int p
Other than that looks fine. Take a look below at full answer that worked for me.
public void printABCNum(int p) {
char textinfo = 65;
String textValue = "";
while (textinfo < 91) {
textValue+=textinfo;
textinfo++;
}
System.out.println(textValue + Integer.toString(p));
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论