Ask Question

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. 13 January, 09:16
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers