Ask Question
22 January, 11:12

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

+3
Answers (1)
  1. 22 January, 11:57
    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?
Find an answer to your question ✅ “Write a method named square that accepts an integer argument and returns the squared of that argument ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers