No rhyme intended.
import java.util.Scanner; public class CalculatorProgram { public static void main(String[] args) { Scanner input = new Scanner(System.in); double firstNumber, secondNumber, answer; System.out.println("Enter the first number:"); firstNumber = input.nextDouble(); System.out.println("Enter the second number:"); secondNumber = input.nextDouble(); answer = firstNumber + secondNumber; System.out.println(answer); } }
When given two doubles, this code occasionally gives an answer that is incorrect (unless I'm seriously overlooking something math-wise). For instance, I gave it 23.2 and 26.4 and it gave an answer of 49.599999999999994. Can you think of any reason why the answer is not a double and also incorrect?