Publicité
Prochain SlideShare
NEW AP Computer Science Exam GridWorld Quick Reference Booklet
Chargement dans ... 3
1 sur 1
Publicité

### Based on how the value in some array position i compares to the value.docx

1. Based on how the value in some array position i compares to the value in its successor position i + 1, each position i in the array a is classified as an u pstep if a [i ] < a [i + 1], a d ownstep if a [i ] > a[ i + 1], and a plateau if a [ i ] == a [ i + 1]. The last position of the array has no such classification, since there is no successor element that we could compare it with. write a method with boolean sameStepShape(int[] a, int[] b) that checks whether the two parameter arrays a and b (your method can assume that these arrays have same length) are the same overall shape in that every position i has the same classification (upstep, downstep or plateau) in both arrays.(java language) Solution public static void compareArrays(int[] array1, int[] array2) { boolean b = false; for (int i = 0; i < array2.length; i++) { for (int a = 0; a < array1.length; a++) { if (array2[i] == array1[a]) { b = true; System.out.println("true"); } else { b = false; System.out.println("False"); break; } } } }
Publicité