--------------------------------------- double[] a; --------------------------------------- a = new double[20]; --------------------------------------- double[] temperatura; temperatura = new double[366]; --------------------------------------- double[] temperatura; ... temperatura = new double[365]; --------------------------------------- double min, max, media; double[] temperature; temperature = new double[366]; int i; --------------------------------------- min = temperature[1]; max = temperature[1]; media = 0; for (i = 1; i <= temperature.length - 1; i++) { if (temperature[i] < min) min = temperature[i]; if (temperature[i] > max) max = temperature[i]; media = media + temperature[i]; } media = media/temperature.length; --------------------------------------- int[] a1; int i; char[] a2, a3; char c; double[] a4; --------------------------------------- int a1[], i; char a2[], a3[], c; double a4[]; --------------------------------------- a1 = new int[10]; a2 = new char[12]; a3 = new char[5]; a4 = new double[7]; --------------------------------------- int a1[] = new int[10], i; char a2[] = new char[12], a3[] = new char[5], c; double[] a4 = new double[7]; --------------------------------------- int[] giorniMese = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; --------------------------------------- int[] giorniMese; giorniMese = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; --------------------------------------- int[] giorniMese; giorniMese = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; --------------------------------------- a1[4] = 5; if (a1[4] > i) { a2[10] = 'p'; a4[0] = a4[1]; } --------------------------------------- char[] a = new char[12]; char[] b = {'a', 's', 'd'}; System.out.println(a.length); System.out.println(b.length); --------------------------------------- for (int i = 0; i <= a.length - 1; i++) a[i] = 0; --------------------------------------- for (int i = 0; i <= a.length - 1; i++) a[i] = i; --------------------------------------- for (int i = 0; i <= a.length - 1; i++) a[i]++; // oppure ++a[i] --------------------------------------- char[] a = new char[10]; for (int i = 0; i <= a.length - 1; i++) a[i] = (char) System.in.read(); --------------------------------------- Incompatible type for =. Explicit cast needed to convert int to char. a[i] = System.in.read(); ^ 1 error --------------------------------------- import java.io.*; class Prova { public static void main (String[] args) throws IOException { int[] a = new int[10]; for (int i = 0; i <= a.length - 1; i++) a[i] = System.in.read(); for (int i = 0; i <= a.length - 1; i++) System.out.println(a[i]); } } --------------------------------------- import java.io.*; class Prova { public static void main (String[] args) throws IOException { int[] a = new int[10]; for (int i = 0; i <= a.length - 1; i++) a[i] = System.in.read(); for (int i = 0; i <= a.length - 1; i++) System.out.println((char)a[i] + " " + a[i]); } } --------------------------------------- int[] a = new int[10]; --------------------------------------- final int N = 10; int[] a = new int[N]; --------------------------------------- double[][] temperatura2 = new double[13][32]; --------------------------------------- int[] giorniMese = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; --------------------------------------- double[][][][] temperatura4 = double[25][32][13][2001] --------------------------------------- double[][] a2 = { {20.0, 19.3, 23.4}, {15.3, 16.0, 17.0} }; --------------------------------------- int[][][] ragged = { {1,2,3},{4},{5,6,7,8,9}}; --------------------------------------- /* Programma per invertire un array */ class InversioneArray { public static void main (String[] args) { int temp, i, a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; for (i = 0; i <= (a.length - 1) / 2; i++) { temp = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = temp; } for (i = 0; i <= a.length - 1; i++) System.out.println(a[i]); } } --------------------------------------- for (i = 0; i < frequenze.length; i++) { "Stampa tanti asterischi quanti frequenze[i]" "Vai a capo"; } --------------------------------------- /* Programma per disegnare l'istogramma di un array di interi*/ class Istogramma { public static void main (String[] args) { int i, j; int[] frequenze = {3, 5, 9, 6, 7, 1, 20, 5, 9, 4, 3, 2}; for (i = 0; i < frequenze.length; i++) { System.out.print(i); System.out.print(": \t"); for (j = 1; j <= frequenze[i]; j++) System.out.print('*'); System.out.println(); } } } --------------------------------------- 0: *** 1: ***** 2: ********* 3: ****** 4: ******* 5: * 6: ******************** 7: ***** 8: ********* 9: **** 10: *** 11: ** --------------------------------------- trovato = false; for (i = 0; i < a.length; i++) if (a[i] == x) { trovato = true; break; } if (trovato) System.out.println(i); else System.out.println("Elemento non trovato"); --------------------------------------- /* Ordinamento per selezione */ import java.io.*; class OrdinamentoSelezione { public static void main (String[] args) throws IOException { final int N = 10; char temp, a[] = new char[N]; for (int i = 0; i < N; i++) a[i] = (char) System.in.read(); for (int i = 0; i < N - 1; i++) for (int j = i; j < N; j++) if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } for (int i = 0; i < N; i++) System.out.print(a[i]); } } --------------------------------------- >javac OrdinamentoSelezione.java >java OrdinamentoSelezione cladbiehfm abcdefhilm --------------------------------------- /* Ricerca Binaria. Assume che l'array a sia ordinato */ import java.io.*; class RicercaBinaria { public static void main (String[] args) throws IOException { final int N = 10; int p, q, m; char x; char[] a = {'a', 'b', 'c', 'd', 'f', 'g', 'h', 'i', 'j', 'k'}; for (int i = 0; i < N; i++) System.out.print(a[i]); System.out.print("\nInserisci l'elemento da trovare: "); x = (char) System.in.read(); p = 0; q = N - 1; System.out.println("p\tm\tq"); do { m = (p + q) / 2; System.out.println(p + "\t" + "\t" + q); System.out.println("\t" + m); if (a[m] < x) p = m + 1; if (a[m] > x) q = m - 1; } while (a[m] != x && p <= q); if (a[m] == x) System.out.println(x + " trovato in posizione " + m); else System.out.println(x + " non trovato"); } } --------------------------------------- >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: k p m q 0 9 4 5 9 7 8 9 8 9 9 9 k trovato in posizione 9 >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: a p m q 0 9 4 0 3 1 0 0 0 a trovato in posizione 0 >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: f p m q 0 9 4 f trovato in posizione 4 >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: g p m q 0 9 4 5 9 7 5 6 5 g trovato in posizione 5 >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: e p m q 0 9 4 0 3 1 2 3 2 3 3 3 e non trovato >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: q p m q 0 9 4 5 9 7 8 9 8 9 9 9 q non trovato >java RicercaBinaria abcdfghijk Inserisci l'elemento da trovare: A p m q 0 9 4 0 3 1 0 0 0 A non trovato --------------------------------------- for (i = 0; i < N; i++) for (j = 0; j < N; j++) C[i,j] = 0; for (i = 0; i < N; i++) for (j = 0; j < N; j++) for (k = 0; k < M; k++) C[i,j] = C[i,j] + A[i,k] * B[k,j];