0

As the title suggests, I came up with this code and I'm not sure why it doesn't do what it's supposed to do.

double value = 0;
String input;

input = scan.nextLine().toUpperCase();

    if (input.substring(0, 1) == "+") {
        value = value + Double.parseDouble(input.substring(1));
    }

Then, I typed the input "+ 25" (without the quotation marks). Also, .toUpperCase is there for another line of code; and then, printed the values to see if I got anything wrong.

System.out.println( input.substring(0, 1));
System.out.println( Double.parseDouble(input.substring(1)) );
System.out.println( value );

first one printed +

second one printed 25.0

and value printed out 0.0

Everything seems to check, why is value still 0.0?

Nadim Baraky
  • 459
  • 5
  • 18

0 Answers0