Java eclipse :Making a Calculator , at the end of the calculation i want
it to ask if you wanna calculate again or shutdown
So this is my calculator , Everything works , x , + , - , /
But i want the user to be able to do 2 things after he got the answere on
his math problem ask user if it wanna continue , if user types in yes he
gets to put in 2 numbers that it Count again if the user types no just
shut down. Sorry if this is messy , im new , and this is the first time i
ask question over here in this forum.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Minscanner = new Scanner(System.in);
int nr1 = Integer.parseInt(Minscanner.nextLine());
int nr2 = Integer.parseInt(Minscanner.nextLine());
int yes = Integer.parseInt(Minscanner.nextLine());//trying to fix
reset
int ans =0;
int reset = J;/trying to make it reset if user types in yes
String anvin = Minscanner.nextLine();
if(anvin.equalsIgnoreCase("+")) {
ans = nr1 + nr2;
}
else if(anvin.equalsIgnoreCase("-")) {
ans = nr1 - nr2;
}
else if(anvin.equalsIgnoreCase("*")) {
ans = nr1 * nr2;
}
else if(anvin.equalsIgnoreCase("/")) {
ans = nr1 / nr2;
System.out.println(ans);
}
if(anvin.equalsIgnoreCase("yes")) {
return;?
}
}
}
No comments:
Post a Comment