Computer Science, asked by rimsonlaguri2003, 8 months ago

What will be the output of the following method for: a) f (28,39) b) f (27,39) public boolean f ( int a, int b ) { boolean c = false; while ( a > 1 && b > 1 ) { if ( a > b ) A - = B; else b - = a; } if ( a == 1 | | b == 1 ) c = true; return ( c ); }

Answers

Answered by vijayp466
1

Answer:

There are so many mistake in this question.

Operator given wrong. ( !! instead of || )

Main method not given in this question

Change public Boolean to public static Boolean.

Full code

class Main {

public static boolean f(int a, int b) {

boolean e = false;

while (a > 1 && b > 1) {

if (a > b) {

a -= b;

} else {

b -= a;

}

}

if (a == 1 || b == 1) {

e = true;

}

return e;

}

public static void main (String[] args) {

int a = 28;

int b = 39;

System.out.print(f(a,b))

}

}

Output: True.

Similar questions