Java:
public class Count2 {
public static void main(String[] args) {
int [] a = { 0, 1, 1, 1, 0}; // Werte dem Array zuordnen
int [] b = { 1, 0, 0, 1, 0}; // Werte dem Array zuordnen
int result3 = dec( a ); // Methode deklarien
System.out.println( result3 ); //Ausgabe result3
int result4 = dec( b ); // Methode deklarien
System.out.println( result4 ); //Ausgabe result3
}
public static int dec(int[] a){ // Methode
int number = 0;
for (int i = 0; i < a.length; ++i){ // i<4
number += a[i] * Math.pow(2, a.length - 1 - i);
}
return number; //gebe number zurück
}
}
ich verstehe leider nicht, was hier (number += a * Math.pow(2, a.length - 1 - i)
+= weist den Wert zu und liefert + als Rückgabewert.
Math.pow (Potenzen) a.length = 5
könnte mir jemand einmal Zahlen einsetzen? Damit ich es verstehe?