Hey guys,
I am new to the forum, and also new to java.
I wanted to make a simple 4 operation calculator, but it wouldn't work.
The problem is that after I enter in my first number, then my operation, and then my final number, the answer is never shown.
Can someone help?
the code:
import java.util.Scanner; public class TheClas { public static void main (String[] args){ float first; float second; String operation; float answer = 0; Scanner theFirst = new Scanner(System.in); Scanner theSecond = new Scanner(System.in); Scanner theOperation = new Scanner(System.in); System.out.println("this is a calculator"); System.out.println("Pick your first number"); first = theFirst.nextFloat(); System.out.println("Pick the operation"); operation = theOperation.nextLine(); System.out.println("Now pick the last number"); second = theSecond.nextFloat(); if(operation.equals('*')){ answer = first*second; System.out.println("the answer is: "+answer); } if(operation.equals('/')){ answer = first/second; System.out.println("the answer is: "+answer); } if(operation.equals('+')){ answer = first+second; System.out.println("the answer is: "+answer); } if(operation.equals('-')){ answer = first-second; System.out.println("the answer is: "+answer+"!"); } } }