Write a calculator program that says welcome to the calculator. It then asks if you want to multiply, divide, add, or subtract. Then once you get into the multiply, divide, add, or subtract loop it will do the calculation output the answer and then ask if you want to do another calculation or exit the program.
Example
Welcome to the calculator!
To multiply use m, to divide use d, to add use a, and to subtract use s
Input first number
Input second number
You chose to multiply. The product is 20
Do you want another calculation (y/n)?
Here is my code so far:
import java.util.Scanner;
public class calculator
{
public static void main(String[] args)
{
char answer;
String input;
int firstnumber;
int secondnumber;
System.out.println ("Welcome to the calculator!");
System.out.println ("To multiply use m, to divide use d, to add use a, to subtract use s");
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println ("Do you want to multiply, divide, add, or subtract? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
if (answer == 'm')
System.out.println ("Input first number: ");
keyboard.nextLine();
input = keyboard.nextLine();
firstnumber = keyboard.nextInt();
System.out.println ("Would you like another calculation (y/n)? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
}
while(answer == 'y')
if(answer == 'n');
System.exit(0);
}
}

New Topic/Question
Reply





MultiQuote





|