Computer Applications
Give output of the following method definition and also write the mathematical operation they carry out:
void test1(int n)
{
for(int x=1; x<=n; x++)
if(n%x == 0)
System. out.println(x);
}
if 12 is passed to n.
Java
User Defined Methods
180 Likes
Answer
1
2
3
4
6
12
Working
This method finds the factors of n.
Answered By
83 Likes
Related Questions
State whether the following statement is True or False :
A method cannot be defined without parameters.
State whether the following statement is True or False :
A method body is enclosed within curly brackets.
Give output of the following method definition and also write the mathematical operation they carry out:
void test2(int a, int b) { while( a != b) { if ( a > b) a = a — b; else a = b — a; } System.out.println(a); }
if 4 and 17 are passed to the function.
Give output of the following method definition and also write the mathematical operation they carry out:
void test3(char c) { System.out.println( (int) c); }
if 'm' is passed to c.