_stan
(320 punti)
1' di lettura

Tema 9

Scrivere un metodo isArrayCrescente che riceve in ingresso un array di interi V e verifica se l’array è crescente.
Ad esempio, sia V l’array così costituito
1 2 3 4 5 6 7 8 9
allora isCrescente (V) = TRUE
 public class tema9 { public static boolean isArrayCrescente (int[] V) { //inizializziamo una variabile boolean impostandola sul valore TRUE, assumendo //che l’array sia crescente boolean crescente = true; // verifichiamo se ogni elemento di V è minore dell'elemento che lo segue for (int i = 0; crescente && i = V[i+1]) crescente = false; return crescente; }  /* Applicazione Di Prova: Inizializziamo tre array su cui testare il metodo; il  * primo array sarà crescente, il secondo array sarà non decrescente, il terzo  * array sarà non crescente. 
*/ public static void main(String[] args) { int[] A = { 1, 2, 5, 7 }; System.out.println(isArrayCrescente (A)); // array crecsente System.out.println(); int[] B = { 1, 2, 5, 5, 7 }; // array non decrescente (ma non crescente) System.out.println(isArrayCrescente (B)); System.out.println(); int[] Z = { 1, 2, 5, 3, 7 }; // un array non crescente System.out.println(isArrayCrescente (Z)); } }