Ask Question

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

+3
Answers (1)
  1. 11 December, 00:56
    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 & 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