Question: Please help with user input with Scanner function in Java. I like to have this below code to work as a calculator with get and

Please help with user input with "Scanner" function in Java. I like to have this below code to work as a calculator with "get and set" methods. As it is now it's only return fix output as I set to 2 + 4 below. How can I correct the code so the user put in for example 2 + 4 and get the sum 6 at print output. Thanks!  public class Main { public static void main(String[] args) { Calc calc = new Calc(); calc.setCalc(); System.out.println(calc.getCalc()); } }
public class Calc { public Calc() { } public int getCalc() { return 2 + 4; } public void setCalc() { } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!