I am learning Java and just been working on creating a little calculator. I am writing one what will allow me to put any number of digits in until I press an equals sign at which point I want the calculator to display the total.
I think that there is a problem with the scanner as while debugging I only get as far as Scanner input = new Scanner (System.in):
In the debugger it say Source not found. This is really strange especially as I am using two Scanners the other class within the same project with no problems at all. As you can tell I used to have 2 scanners in this piece but I read that this should not work so I am now using one. Here is the code...
package Calculator;
import java.util.Scanner;
public class Calculator3 {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
// Scanner opin = new Scanner (System.in);
String operative = input.next();
double numb = input.nextDouble();
int answer = 0;
int calc = 1;
System.out.print("#######################################" + "\n");
while (operative.equalsIgnoreCase("="))
{
System.out.print("Interger " + calc + " :");
System.out.print("Type your Operative :");
if (operative.equals("+"))
answer += numb;
{
if (operative.equals("-"))
answer -= numb;
{
if (operative.equals("/"))
answer /= numb;
{
if (operative.equals("*"))
answer *= numb;
{
}
}
}
}
calc += 1;
}
System.out.print("#######################################" + "\n");
System.out.println("Your answer is: " + answer + ".");
}
}