Ask Question
23 March, 13:27

Write a method named square that accepts an integer argument and returns the squared of that argument

+1
Answers (1)
  1. 23 March, 15:47
    0
    public static int squared (int num) {

    return num*num;

    }

    Explanation:

    A complete java programming calling the method squared is given below:

    import java. util. Scanner;

    public class SquareExample {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter the Number to Square");

    int n = in. nextInt ();

    //Call the square method and pass the int number

    int squareValue = squared (n);

    //Print the the Square of the Number

    System. out. println (squareValue);

    }

    public static int squared (int num) {

    return num*num;

    }

    }

    In Java, a method is declared with its signature which is specified with an optional access modifier (in this case public), the return type (int in this case), the name of the method (squared) and the parameters in brackets.

    Then we specify the methods behaviour by the codes within the braces following, in this case we simply find the square of n and return it.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method named square that accepts an integer argument and returns the squared of that argument ...” 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