In this code, when I'm using == it gives "Error converting a number to a string (invalid format)"
But when .equals is used it's working!
Then what is the difference here between them? I understand from the lesson that one is reference comparision while other is value, and .equals() will verify the values, but when == is used then what this error means of converting number to string?
package com.codegym.task.task05.task0529;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Console piggy bank
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
int sum = 0, num;
String a, b = "name";
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
while(true) {
a = bufferedreader.readLine();
if(a == b) {
System.out.println(sum);
break;
}
else {
num = Integer.parseInt(a);
sum += num;
}
}
}
}