It's a code to get a common divisor. The first code fails and the second code does not(This method must return a result of type int). I really want to know why....
If we don't have a common divisor, we want to return -1.
public class aaa{
public static int function(int a, int b){
for(int a = 1; i <= a; i++){
if ( a % i == 0){
b--;
}if ( b == 0) {
return i;
}else {
return -1;
}
}
}
public static void main(String[] args) {
system.out.println("The 5th common measure of 1000 is" + fuction(1000, 5));
}
}
public class aaa{
public static int function(int a, int b){
for(int a = 1; i <= a; i++){
if ( a % i == 0){
b--;
}if ( b == 0) {
return i;
}
} return -1;
}
public static void main(String[] args) {
system.out.println("The 5th common measure of 1000 is" + fuction(1000, 5));
}
}