When I run it it says the local variable answer may not have been initialized but when I made the if-then-else statement I though that would have initialized itimport java.util.Scanner; public class startingpoint { public static void main (String args[]){ Scanner sc = new Scanner (System.in); double type,fnum, snum, answer; System.out.println("Enter one of three calculator modes, 1 (Multiplication),2 (Division), 3 (Addition). or 4(Subtraction)"); type = sc.nextDouble(); System.out.println("Please enter your first number now"); fnum = sc.nextDouble(); System.out.println("Please enter your second number now"); snum = sc.nextDouble(); if (type == 1){ answer = fnum * snum; } else if (type == 2){ answer = fnum / snum; }else if (type == 3){ answer = fnum + snum; }else if (type == 4){ answer = fnum + snum; } System.out.println("Your answer is"); System.out.println(answer); } }
Never mind I found out the problem thanks to Cornix, I forgot to add the else