Computer Science, asked by kelly13, 6 months ago

Write a java program of given question using method ( RECEIVING AND NOT RETURNING THE VALUE) Class 10th ICSE

Attachments:

Answers

Answered by sameerpawankum25
0

Answer:

Ans: Platform is the environment in which programs execute. Instead of interacting with the Operating System directly, Java programs runs on a virtual machine provided by Java, therefore Java is often referred to as a platform also.

Answered by sridevireddy171816
1

Explanation:

add_int(int x,int y) - This part of code should be clear that 'add_int' is the name of method and it is taking two parameters of type int.

int add_int(int x,int y) - 'int' before the method name means that this method will return an integer. i.e. we will get some integer value whenever we will call this method.

return x+y; - This part returns an integer having the value 'x+y' since our method has to return an integer.

Now come to the main method

int z = add_int(x+y); - We are calling 'add_int' method by passing two integers 2 and 4. And this will return 'x+y' i.e. '2+4'. So, this statement is equivalent to:

int z = 2+4; or int z = 6; (6) returned by 'add_int(2,4)'

This method is returning 'double'( x*y )'. And the main method statement is equivalent to:

double z = 10.2*23.4; or double z = 238.67999999999998;

Calling a method inside another

Yes, we can call a method inside another method. We have already done this. We were calling our functions inside the main function. Now look at an example in which there are two user-defined functions. And we will call one inside another.

A number is divisible by 6 if it is divisible by both 2 and 3. We have a method div_2 which will return 1 if the given number is divisible by 2. Another method that we have defined is dev_6 which calls div_2 inside itself.

if( div_2(b)==1 && b%3 == 0 ) - So if div_2 will returns 1, means that the number is divisible by 2. And if b%3==0 is true, it means that 'b' is divisible by 3. So, if it is divisible by both 2 and 3, then it is divisible by 6 also.

Recursion

Recursion is the calling of a method within the same method.

Let's consider an example in which we have to calculate the factorial of a number.

Similar questions