Results 1 to 4 of 4
Thread: How to create a battleship grid?
- 11-16-2012, 03:19 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
- 11-16-2012, 04:28 AM #2
Re: How to create a battleship grid?
A nested loop.
- 11-16-2012, 09:11 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 14
- Rep Power
- 0
Re: How to create a battleship grid?
The easiest way I can think of would be a two dimensional array.
That will just print the array out as a block of 8x8 0's. This could just as easily be an 8x8 array of objects be it battleships, cruisers etc.Java Code:public class Shipgrid { public static void main(String[] args){ int[][] shipGrid = new int[8][8]; for (int i = 0; i < shipGrid.length; i++){ for ( int j = 0; j < shipGrid[i].length; j++){ shipGrid[i][j] = 0; } } for (int i = 0; i < shipGrid.length; i++){ System.out.println(); for ( int j = 0; j < shipGrid[i].length; j++){ System.out.print(shipGrid[i][j]); } } } }Last edited by Jingoism; 11-16-2012 at 09:13 AM.
- 11-16-2012, 09:15 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Open Grid Scheduler/Grid Engine
By java software in forum Java SoftwareReplies: 0Last Post: 03-27-2012, 07:00 PM -
Battleship UML help
By Lucid15 in forum New To JavaReplies: 0Last Post: 03-12-2012, 04:15 AM -
battleship in java
By matthewandalex5 in forum Advanced JavaReplies: 2Last Post: 03-01-2012, 03:13 PM -
How Can I Create a Simple Grid with a GridLayout?
By geeeeky.girl in forum AWT / SwingReplies: 7Last Post: 01-07-2009, 03:31 AM -
[SOLVED] How to create a Grid?
By Nakira in forum New To JavaReplies: 11Last Post: 11-12-2008, 10:45 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks