import java.util.ArrayList;
ArrayList<int[]> list = new ArrayList<int[]> ();
list.add(new int[] {1,2});
list.add(new int[] {3,4});
int xmin = 0;
int ymin = 0;
for(int i = 0; i < list.size(); i++) {
int[] el = list.get(i);
if(list.get(i)[0] < xmin) {
...
}
if(list.get(i)[1] < ymin) {
....
}
}
int xpos = 0;
int ypos = 0;
final String[] states = { "FaceUp", "FaceDown", "FaceLeft", "FaceRight"};
String state = "FaceUp";
InfiniteBlockWorld w;
public static final int UP = 0;
public enum Direction {
North,
South,
West,
East
}
public void next() {
Boolean color = w.getCellColor(xpos, ypos);
String newState;
Boolean newColor;
Direction d;
state = newState;
w.setCellColor(xpos, ypos, newColor);
switch(d) {
case North:
ypos --;
}
}
/* illustration of how to return multiple values from a method in Java */
package lecture;
public class Returned {
/* data object used to store cal */
public static class PersonCal {
String name;
int cals;
public PersonCal(String name, int cals) {
this.name = name;
this.cals = cals;
}
public String toString() {
return "PersonCal(" + name + "," + cals + ")";
}
}
/* return both Person name (String) and calories (Integer) as an Object[] */
public static Object[] getPersonCal() {
String name = "asdasdas";
int cals = 1235;
Object[] ret;
ret = new Object[2];
ret[0] = name;
ret[1] = new Integer(cals);
return ret;
}
/* return both Person name and calories as a "data" object */
public static PersonCal getPersonCalObject() {
String name = "asdasdas";
int cals = 1235;
return new PersonCal(name, cals);
}
public static void main() {
Object[] result = Returned.getPersonCal();
String name = (String) result[0];
Integer cals = (Integer) result[1];
System.out.println(String.format("%s %d", name, cals));
PersonCal p = getPersonCalObject();
System.out.println(p.toString());
}
}
import lecture.Returned;
Returned.main();