Hello,
I make a program loop..but it doesn't work as i want ><" !
this is the OUTPUT -look careful, please- :
Welcome to our miniCalculator
if you want to use add, enter add
if you want to use subtraction, enter sub
if you want to use division, enter div
if you want to use multiplication, enter mul
if you want to exit, enter bye
add
Please enter First number
4
Please enter Second number
5
4 + 5 = 9.0
if you want to use add, enter add
if you want to use subtraction, enter sub
if you want to use division, enter div
if you want to use multiplication, enter mul
if you want to exit, enter bye
Please enter First number
this is the code:
import java.util.Scanner;
public class MiniCalculator {
String display; // for displaying calculation result.
static String operation, store1;
static double memory;
static double store;
static double number1,number2;
static boolean trueOrfalse;
public static void main(String [] args) {
Scanner in = new Scanner (System.in);
System.out.println ("Welcome to our miniCalculator");
while(trueOrfalse == false){
System.out.println ("if you want to use add, enter add");
System.out.println ("if you want to use subtraction, enter sub");
System.out.println ("if you want to use division, enter div");
System.out.println ("if you want to use multiplication, enter mul");
System.out.println ("if you want to exit, enter bye");
operation = in.nextLine();
if (operation.equalsIgnoreCase("bye")){
trueOrfalse = true ;
System.exit(0);
break;
}
System.out.println ("Please enter First number");
number1 = in.nextDouble();
System.out.println ("Please enter Second number");
number2 = in.nextDouble();
if (operation.equalsIgnoreCase("add")){
store = (MiniCalculator.addTwoNumbers());
System.out.print( (int)number1 + " + " + (int)number2 + " = ");
System.out.println (store + "\n");
}
else if(operation.equalsIgnoreCase("sub")){
store = (MiniCalculator.subtractTwoNumbers());
System.out.print( number1 + " - " + number2 + " = ");
System.out.println (store + "\n");
}
else if(operation.equalsIgnoreCase("div")){
store1 = (MiniCalculator.divideTwoNumbers());
System.out.print( number1 + " ÷ " + number2);
System.out.println (store1 + "\n");
}
else if(operation.equalsIgnoreCase("mul")){
store = (MiniCalculator.multiplyTwoNumbers());
System.out.print( number1 + " × " + number2 + " = ");
System.out.println (store + "\n");
}
}
}
...
...
...
}
}
Please HELP me T_T !