如何在Java中设置网格表格

huangapple 未分类评论58阅读模式
英文:

How do you set up grid tables in Java

问题

在一个网格中,比如说是500乘500的,我需要知道特定方格的值。答案可能是是或者否。是否有东西存在。可以将其想象成一张方格纸;方格是否被涂色了。

如何在Java中设置这个表格?一个例子是;我想要知道在位置,x=400,y=400,这个方格是否被占据。

我对如何实现感到困惑。是不是可以使用数组来实现?

如果可以的话,请为我展示一个如何声明这个表格的例子,如何从这个表格中读取数据以及如何向这个表格中写入数据。

感谢你的帮助。

英文:

I need a hint, a big hint.

In a grid, say 500 by 500, I need to know the value of that square. The answer would be yes or no. Is something there or not. Think of it as piece of graph paper; has the square been colored in, or not?

How would I set up this table up in Java? An example would be; I want to see if at location, x=400, y=400; is this square occupied or not.

I am just confused by how that’s done. Is that what arrays are used for?

If you would please include an example of how I would declare this table, how I would read from this table and how I would write to this table.

Thank you for helping out.

答案1

得分: 0

你可以使用多维数组来存储表的行和列。然后,您可以相应地插入数据,并使用索引检查值是true还是false。这是一个链接。https://www.geeksforgeeks.org/multidimensional-arrays-in-java/

如果您创建一个(多维数组),然后将其打印到屏幕上,这将是有意义的。然后,您可以填充它并通过索引检查值。例如,[x][y]返回true。

英文:

You can use a multi-dimensional array to hold the rows and columns of a table. Then you can insert data accordingly and check whether a value is true or false using indexes. Here is a link. https://www.geeksforgeeks.org/multidimensional-arrays-in-java/

it will make sense if you make one(multidimensional array) then print it to your screen. then you can populate it and check for values by the indexes. example [x][y] returns true

huangapple
  • 本文由 发表于 2020年4月9日 08:25:14
  • 转载请务必保留本文链接:https://java.coder-hub.com/61112086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定