Results 1 to 2 of 2
  1. #1
    luigihs is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Battleships BlueJ

    Hello Im trying to do print out my board like this:


    but what I got is this


    what I want is to display like in the first picture in vertical way 0 - 9 but the only thing I can do is only showing one only number. I need help please thank you this is my code:
    Java Code:
    private void setUpShots()
        {
         
            for (int row=0; row < shots.length; row++) {
                for (int col = 0; col < shots[0].length; col++) {
                    shots[row][col] = '.';
                }
            }
        }
    
        public void printBoard() {
            
            System.out.println("012456789");
            for (int row=0; row < 10; row++) {
              System.out.print("0");
                for (int col = 0; col < 10; col++) {
                 System.out.print('.');
                    } 
                     System.out.println();
                }
               
            }

  2. #2
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Battleships BlueJ

    Try making an array with all the numbers in them, then using a for loop to run through them all and print them, there is probably a much simpler way, but I'm a noob too. :P

    Java Code:
    public class Practice {
    	private static int numbers[] = {1,2,3,4,5,6,7,8,9,10};
    	public static void main(String[] args) {
    		for(int x = 0; x < numbers.length; x++){
    			System.out.println(numbers[x]);
    		}
    	}
    
    }
    Last edited by Darkzombies; 11-27-2012 at 12:50 AM.

Similar Threads

  1. bluej help
    By xpanhol in forum Java Applets
    Replies: 4
    Last Post: 01-29-2012, 12:46 AM
  2. BlueJ - UML
    By Nghi97 in forum New To Java
    Replies: 5
    Last Post: 11-28-2011, 11:03 AM
  3. XML Battleships
    By rizowski in forum New To Java
    Replies: 0
    Last Post: 02-08-2011, 03:25 PM
  4. Not another Battleships post..
    By noobForever in forum New To Java
    Replies: 4
    Last Post: 01-07-2011, 06:26 PM
  5. Need help with blueJ
    By samd89 in forum Other IDEs
    Replies: 6
    Last Post: 12-06-2010, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •