Ask Question
11 May, 17:47

Create a program that used a main method and a method named "subtractTwoNumbers () ". Your subtractTwoNumbers () method should require three integers to be sent from the main method. The second and third numbers should be subtracted from the first number.

+3
Answers (1)
  1. 11 May, 20:30
    0
    import java. util. Scanner;

    public class num4 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("First number:");

    int fnum = in. nextInt ();

    System. out. println ("Second number:");

    int snum = in. nextInt ();

    System. out. println ("Third number:");

    int tnum = in. nextInt ();

    //Call method subtractTwoNumbers

    System. out. println ("Subtracting the second and third num from the first yeilds" +

    " "+subtractTwoNumbers (fnum, snum, tnum));

    }

    public static int subtractTwoNumbers (int fnum, int snum, int tnum) {

    int sub = fnum - (snum+tnum);

    return sub;

    }

    }

    Explanation:

    Java is used to solve this problem Use Scanner class to receive three values and stored them in variables as fnum, snum and tnum for first number, second number and third number respectively Create the method subtractTwoNumbers () that subtracts the sum of snum and tnum from fnum and returns the value In the main method call subtractTwoNumbers () and pass the three numbers as arguments
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Create a program that used a main method and a method named "subtractTwoNumbers () ". Your subtractTwoNumbers () method should require ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers