Salve ragazzi, sto impazzendo![]()
![]()
![]()
Ecco il testo:
Scrivere un metodo che, dati due array monodimensionali a e b di interi,
restituisce true se per ogni elemento b[i] di b esiste almeno un elemento a[j] di a tale che
a[j] divide b[i]. Ad esempio, dati a = {2,3} e b = {6,3,6,10,2}, il metodo restituisce true,
mentre se b = f6,3,5,2g, allora il metodo restituisce false.
Questa è la mia versione :
Mi restituisce sempre false....codice:class Array9{ public static void main (String [] args){ int [] a = {2,3}; int [] b = {6,3,6,10,2}; int j = 0; int i = 0; System.out.println(array(a,b,i,j)); } public static boolean array (int a [], int [] b , int j, int i){ while (j<a.length && i<b.length){ if(a[j] % b[i]==0){ j=0; i++; } else{ j++; } } if(j>=a.length){ return false; } return true; } }
Come mai?

Rispondi quotando