Looping and Arrays Slides
Looping and Arrays Slides
statement ;
someValue factorial
int someValue = 4;
int factorial = 1; 4 1
while(someValue > 1) {
factorial *= someValue;
someValue--;
System.out.println(factorial); // displays 24
do
statement ;
while ( condition )
int iVal = 5;
do {
System.out.print(iVal); 5 * 2 = 10
System.out.print(“ * 2 = “); 10 * 2 = 20
iVal *= 2; 20 * 2 = 40
System.out.println(iVal);
do {
System.out.print(iVal);
iVal *= 2;
System.out.println(iVal);
}
float[] theVals = new float[3];
theVals[0] = 10.0f;
theVals 10.0f 20.0f 15.0f
theVals[1] = 20.0f;
0 1 2
theVals[2] = 15.0f;
-
-
-
float[] theVals = new float[3];
theVals[0] = 10.0f;
theVals[1] = 20.0f;
theVals[2] = 15.0f;
sum += theVals[index];
System.out.println(sum); // displays 45
float[] theVals = new float[3];
theVals[0] = 10.0f;
theVals[1] = 20.0f;
theVals[2] = 15.0f;
sum += theVals[index];
System.out.println(sum); // displays 45
float[] theVals = new float[3];
theVals[0] = 10.0f;
theVals[1] = 20.0f;
theVals[2] = 15.0f;
sum += theVals[index];
System.out.println(sum); // displays 45
float[] theVals = {10.0f, 20.0f, 15.0f };
sum += theVals[index];
System.out.println(sum); // displays 45
float[] theVals = { 10.0f, 20.0f, 15.0f };
sum += currentVal;
System.out.println(sum); // displays 45
-
-
-
-
-
-
-
-
-