class Student {
private String name;
public void setName (String name) {this.name = name;}
}
String [] names = new String [15]; boolean [] bits = new boolean [99];which creates an array of size 15 with indices 0..14
coinNames[4] = "half";This could be done within a loop, e.g.
a[i] = i*7;
double [] x = {1.0, 2.71, 3.14, 4.0};
int i = 0;
while (i < x.length) {
x [i] += 1.0;
}
System.arraycopy(sourceArray, sourceAt,
targetArray, targetAt, elementCount);
all the element positions must be valid, specifically:
if (a > b) {
x = 3.0;
} else if (a > c) {
x = 2.2;
} else {
a = 99;
}
beforeLoop (); for (beforeLoop (); condition (); update ()) {
while (condition ()) {
loopBody (); loopBody ();
update ();
} }
while(x > 0) {
x -= y;
y = y * 2;
}
do {
x -= y;
y = y * 2;
} while (x > 0);
for (int i = 0; i < a.length; i++) {
a [i] *= 2;
}
int quotient = 11 / 4;
int remainder = 11 % 4;
Random myRandomGenerator = new Random (); int random = myRandomGenerator.nextInt () % 2;
the result is always zero or one
try {
/* code which may throw exception */
} catch (exceptionClass1 variable1) {
/* code which handles exception of type exceptionClass1 */
} catch (exceptionClass2 variable2) {
/* code which handles exception of type exceptionClass2 */
} finally {
/* code executed after try or catch */
}
try {
/* something that may cause IOException */
} catch (IOException error) {
error.printStackTrace ();
System.exit (1);
}