double a new double 10 double b a
חידודים לגבי מערכים double[] a = new double [10]; double[] b = a; for (int i = 0; i<a. length; i = i+1) a[i] = i; b[4] = 40; int[] x = {1, 2, 3}; int[] y = {1, 2, 3}; x[2] = 4;
מציאת אינדקס איבר מינימלי int[] arr; int size = sc. next. Int(); arr = new int[size]; for (int i=0; i<size; i=i+1) arr [i] = sc. next. Int(); : תנאי קדם min. Index=0, min. Val=arr[0], i=1, size>0 : טענה נשמרת min. Val is the minimal value in arr[0. . i-1], min. Index is the index of the minimal value in arr[0. . i-1] 0 i arr. length int min. Index= 0; int min. Val = arr[0]; for (int i=1; i<arr. length; i=i+1) { if (arr[i] < min. Val) { min. Index= i; min. Val = arr[i]; : תנאי בתר } min. Index is the index of the minimal value in arr } System. out. println("The index of the minimal value is "+min. Index);
"n מימוש "הראשוניים עד int n = sc. next. Int(); int[] primes = new int[n]; // To keep the primes found so far int prime. Index = 0; // Index of the next prime found for (int x=2; x<=n; x=x+1) { // x is the current candidate boolean is. Prime = true; // Innocent till found guilty for(int i=0; i<prime. Index && is. Prime && (primes[i]*primes[i])<=x; i=i+1){ if (x%primes[i] == 0) is. Prime = false; } // for (i. . . ) if (is. Prime) { primes[prime. Index] = x; prime. Index = prime. Index+1; } // if } // for (x. . . ) for (int i=0; i<prime. Index; i=i+1) System. out. println(primes[i]);
- Slides: 13