This is my code. I'm super new to Java. Basically trying to make a super-easy calculator. I get the in the title named error on the else if(add){...etc. Would appreciate any help! Thanks!
import java.io.Console;
import java.util.Scanner;
public class letsgo {
@SuppressWarnings("resource")
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Hello, and welcome to my first calculator.");
System.out.println("Please type your first number here:");
int num1 = input.nextInt();
System.out.println("Please type your second number here");
int num2 = input.nextInt();
boolean add;
boolean subtract;
int answerAdd = num1 + num2;
int answerSubtract = num1 - num2;
boolean tryAgain;
do{
add = input.hasNext("add");
subtract = input.hasNext("subtract");
System.out.println("Do you want to subtract or add?" );
if(subtract){
System.out.println(answerSubtract);}
else if(add){
System.out.println(answerAdd);}
else("AssignmentOperator Expression" (tryAgain)){
System.out.println("Please say add or subtract instead: ");}
}
while(tryAgain);
Aucun commentaire:
Enregistrer un commentaire