Hey, I'm new to java, and I'm trying to make a calculator, with the choice of + or -. My code is:
import java.util.Scanner; public class Funk { public static void main (String[] args) { double first; double second; String plussminus; double sum = 0; Scanner input = new Scanner (System.in); Scanner pm = new Scanner (System.in); System.out.print("First number: "); first = input.nextDouble(); System.out.print("+ or -? "); plussminus = pm.nextLine(); System.out.print("Second number: "); second = input.nextDouble(); if (plussminus == "plus") { sum = first + second; } else if (plussminus == "minus") { sum = first - second; } else { System.out.println("You did something wrong.");} System.out.println(sum); } }
But it always says "You did something wrong.", and i get the answer "0.0". I've tried for quite some time now, but can't get it to work.