Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions