java 求救
见代码:
Java code:
import java.util.ArrayList;
import actor.Sheep;
public class BoundedGrid<E>
{
private Object[][] occupantArray; // the array storing the grid elements
public E get(Location loc)
{
if (!isValid(loc))
throw new IllegalArgumentException("Location " + loc
+ " is not valid");
return (E) occupantArray[loc.getX()][loc.getY()];
}
public ArrayList<Location> getEmptyLocations(Location l)
{
ArrayList<Location> theLocations = new ArrayList<Location>();
for (int r = -1; r < 2; r++)
{
for (int c = -1; c < 2; c++)
{
Location loc = new Location(l.getX() + r, l.getY() + c);
if (loc.getX() >=0 && loc.getY() >=0 && get(loc) == null)//get(loc) == null就可以
theLocations.add(loc);
}
}
return theLocations;
}
public ArrayList<Location> getSheepLocations(Location l)
{
ArrayList<Location> theLocations = new ArrayList<Location>();
// Look at all grid locations.
for (int r = -1; r < 2; r++)
{
for (int c = -1; c < 2; c++)
{
Location loc =
相关问答:
字符流的读和写最终在底层都是通过字节流来完成的吗? 读写文本文件字符流应该就可以了吧。。
各位大哥大姐帮帮忙阿
Java流包括字节流和字符流,字节流通过IO设备以字节数据的方式读入,而字符流则是通过字节流 ......
import java.io.*;
class FileTest
{
public static void main(String [] args) throws Exception
{
File fDir=new File(File.separator);
String strFile="java源代码测试"+File.separato ......
我们有项目想组建一个开发团队,
主要用 tomcat,java,struts2,我们的核心成员都是经验非常丰富的系统设计师,
如果您在天津,同时对java比较感兴趣,
可以加入我们。
希望要求
1。爱好编程
......
import java.util.*;
class Tiger{}
public class P378 {
public static void main(String[] args) {
//为什么可以这么做
List<String> ls=new Test1().makeArrayList(new Tiger());
}
}
clas ......
用java 模拟购物车
也就是有一个框框,里面是商品列表(商品名字和价格)可以添加、删除列表里的商品
鼠标点击一个商品后,就在新的一个框框里显示出来,并且也可以删除操作、总和价格
就 ......