-1

I am a beginner in Java just started not even a month ago. I need help adding a scanner for user input, which is being operated mathematically by the method. I would like this to be done by adapting the scanner to my methods which I am mainly puzzed about. If you can add comments on how your solution works that would be appreciated. Thank you for anyone giving it a try.

class Main {

public static void main(String[] args) {
    // make the two numbers able to be be added, subtracted, multipled, and divided
    Main n = new Main();
    System.out.print("Adding and Subtracting: ");
    n.addition(4, 6);
    System.out.print(" and ");
    n.subtract(6, 4);
    System.out.println();
    System.out.print("Multiplying and Dividing: ");
    n.multiply(4, 6);
    System.out.print(" and ");
    n.divide(4, 6);
}
//keep all the variables in the same method
//I need a scanner to take input from the user for the numbers the user wants which will be added, subtracted, multiplyed, and divided.

public void addition(int x, int y)
{
    System.out.print(x + y);
}
public void subtract(int x, int y)
{
    System.out.print(x - y);
}
public void multiply(int x, int y)
{
    System.out.print(x * y);
}
public void divide(int x, double y)
{
    System.out.print(x / y);
}

}

Beaner21
  • 13
  • 4

0 Answers0