简体   繁体   English

不使用局部变量变量的值

[英]The value of the local variable variable is not used

hi I'm new in this I don't know nothing about this if you can help me please I will apreciate. 嗨,我是新来的,如果您能帮助我,我对此一无所知,我将不胜感激。

Here is my tried of code 这是我尝试的代码

package paquete; 包装盒

class Main {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    int variable;
    variable = 5;

    System.out.println("variable");

}

} }

that is the mistake that eclipse give me it says that the mistake is int variable; eclipse给我的错误就是错误是int变量。 I don't know why when i created the class main i selected public class main because it doesn't show me class default I think that is the mistake but I can selected. 我不知道为什么当我创建班级主班时选择了公共班级主班,因为它没有显示班级默认值,我认为这是错误的,但是我可以选择。 please if someone can help me. 请有人帮助我。

The quotes around the print parameter make it a regular old string. print参数周围的引号使它成为常规的旧字符串。 If you want to print the variable value itself, leave out the double quotes. 如果要打印变量值本身,请省略双引号。 As mentioned before, make it System.out.println(variable); 如前所述,使其成为System.out.println(variable); .

The issue is that you have declared a variable, 'variable' on this line 问题是您在此行上声明了一个变量“ variable”

   int variable;

But you never use that variable. 但是您永远不要使用该变量。 However if you change your println statement, you can make this warning disappear 但是,如果更改了println语句,则可以使该警告消失

System.out.println("variable: " + variable);

By putting quotes around variable in System.out.println("variable"); 通过在System.out.println("variable");周围System.out.println("variable");引号 you are outputting the string (word) variable. 您正在输出字符串(单词)变量。 When you want to output the literal value of the variable, you don't put quotes around it. 当您要输出变量的字面值时,不要在其周围加上引号。 For example System.out.println(variable); 例如System.out.println(variable); would output 5 (as that is what you assigned to variable 将输出5 (因为这是您分配给variable

Actually you are trying to print variable text 实际上,您正在尝试打印variable文本

 System.out.println("variable");

so change to 所以改为

  System.out.println(variable);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM