Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Array table question

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array table question

    import javax.swing.JOptionPane;
     
     
    public class circle{
      //Instance variables
      /*
       * 2D array of chars for the board
       */
     
    	public static void main(String[] args)
    	{
    		circle o = new circle();
    		o.print();
     
     
     
     
    	}
     
     
      private char[][] board;
     
      /** 
       * Creates a board where each
       * square holds the underline '_' character.
       */
      public circle(){
        board = new char[2][3];
        for (int row = 0; row < 2; row ++){
          for (int col =  0; col < 3; col++){
            board[row][col] = '_';
          } // end of inner loop
        } // end of outer loop
      } 
     
     
      public char get(int row, int col){
        return board[row][col];
      }
     
     
     
     
      public void print(){
        int col;
        System.out.println();
        for (int row = 0; row < 2; row ++){
          if(row == 0){
            System.out.print("Start"+ "\t");
          }
          else {
            System.out.print("Finish"+ "\t");
          }
          for (col =  0; col < 3; col++){
            System.out.print(board[row][col] + " ");
          } // end of inner loop
          System.out.println();
        } // end of outer loop   
      }
    }

    This prints:
    Start _ _ _
    Finish _ _ _


    I was wondering how i could change the "_" to "X" if the user inputs a correct answer :S


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Array table question

    how i could change the "_" to "X"
    Find Where is the "_" stored and change its value to "X" when the user inputs a correct answer.

    I don't see where the user's answers are received or how they are related to the array that holds the "_"s.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Array question
    By knightmetal in forum Collections and Generics
    Replies: 3
    Last Post: April 7th, 2012, 12:05 AM
  2. 2 array question
    By w.kit in forum Java Theory & Questions
    Replies: 1
    Last Post: January 16th, 2012, 07:56 AM
  3. Help on 2D Multi Table Array
    By clevel211 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 1st, 2011, 04:28 AM
  4. HTML table to 2D array parser
    By Neruk in forum Algorithms & Recursion
    Replies: 2
    Last Post: January 28th, 2011, 07:16 AM
  5. A question about an array
    By faizana2006 in forum Collections and Generics
    Replies: 2
    Last Post: October 28th, 2009, 04:36 PM