• Post Reply Bookmark Topic Watch Topic
  • New Topic

Warning while using boolean datatype in my program, Execution success.  RSS feed

 
Shivv Krishna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

I am getting notification about "The value of the local variable result not used" in my program when i am using boolean data type.
But code execution was successful. Results are also displayed accurately.

I am using Eclipse, there i i have noticed this warning.



* program to practice about comparison operators */
public class compoperators {

public static void main(String[] args) {
boolean result;
int numb1=100, numb2=95;
// result=numb1>numb2;
System.out.println("Both number equal: " + (result=numb1==numb2));
System.out.println("Numb1 graterthen numb2 : " + (result=numb1>numb2));
System.out.println("Numb1 lessthen numb2 : " + (result=numb1<numb2));
System.out.println("Numb1 graterthaneequal to numb2 : " + (result=numb1>=numb2));
System.out.println("Numb1 lessthaneequal numb2 : " + (result=numb1<=numb2));
System.out.println("Numb1 notequal to numb2 : " + (result=numb1!=numb2));
}

}

Please let me know is there anything that i have missed in this code.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable result is only assigned a value, but you are not reading the value of the variable anywhere. Therefore, the variable isn't necessary at all. You can just remove it.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is also potentially confusing to have an assignment inside brackets like that.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!