Ask coding questions

← Back to all posts
i made java calculator and im lost on how to fix some of the errors
TaiwoMakinwa (0)

I was supposed to create a java calculator using parameters allowing someone to input 2 integer values and an operation (+ or -) and it outputs an answer.

Comments
hotnewtop
Coder100 (18057)

1. wrong class

Your class has to be called Main because that is what your file is called, so:

public class Main {

on line 2

Then, to set a value (lines 14 and 15)
you do not need to name the type

a = input.nextInt();
b = input.nextInt();

and you don't have to define keyboard multiple times so remove those on line 17.

Finally, you never defined methods for addition and subtraction so add those.