#1 3. Mai 2007 eclipse... hey ich habe ein problem..unter eclipse...laut unserem lehrer sollen wir in eclipse mit feldern arbeiten und da jetz den mittelwert den größten wert usw. usw. finden , NUR WIE? und erklärt bekommen wir es auch nicht wirklich bitte hilfe + Multi-Zitat Zitieren
#2 3. Mai 2007 AW: eclipse... ich verstehe zwar nicht ganz wo dein problem liegt, bei eclipse oder beim programmieren aber hier ist mal der code: Code: public class mittlewertFeld { public static void main(String[] args) { int[] feld={17,20,32,5,67,14}; double summe=0; for(int i=0;i<feld.length;i++){ summe=summe+feld[i]; } double durchschnitt = summe/feld.length; System.out.println("Der Durchschnitt ist: "+durchschnitt); } } + Multi-Zitat Zitieren
#3 5. Mai 2007 AW: eclipse... Größter Wert Code: public class maxWert { public static void main(String[] args) { int[] feld={17,20,32,5,67,14}; int max = 0; for(int i=0; i<feld.length; i++){ if(max < feld[i]) { max = feld[i]; } } System.out.println("Der größte Wert ist: " +max); } } + Multi-Zitat Zitieren
#4 7. Mai 2007 AW: eclipse... @ EvilKenny du hast ein kleiner denkfehler drin. falls nur negative werte in dem feld stehen würden, hättest du als max-wert 0. also machen wir das draus: PHP: public class maxWert { public static void main ( String [] args ) { int [] feld ={ 17 , 20 , 32 , 5 , 67 , 14 }; int max = feld [ 0 ]; for( int i = 0 ; i < feld . length ; i ++){ if( max < feld [ i ]) { max = feld [ i ]; } } System . out . println ( "Der größte Wert ist: " + max ); } } PHP: public class minWert { public static void main ( String [] args ) { int [] feld ={ 17 , 20 , 32 , 5 , 67 , 14 }; int min = feld [ 0 ]; for( int i = 0 ; i < feld . length ; i ++){ if( min > feld [ i ]) { min = feld [ i ]; } } System . out . println ( "Der kleinsteWert ist: " + min ); } } gruß wollknoll + Multi-Zitat Zitieren