Carteeeer
Carteeeer

Reputation: 21

How do I use an integer from an other class in a method?

I have a lab for a high school comp sci class, I take integer input in the driver class, and pass that to a method in another class that uses the number to do a calculation and return the answer.

Whats an easy way of doing this?

Upvotes: 0

Views: 39

Answers (1)

tmillward
tmillward

Reputation: 32

Depending on what you're trying to produce with the output, you can simply use a "get" function inside your driver class after you've accepted your user input. The purpose of this function is to simply return the value of your variable.

Eg.

public int getVariable() {
     return x;
}

And then

secondClass.calculation(driver.getVariable());

Hope this helps!

Upvotes: 1

Related Questions