Results 1 to 3 of 3

Thread: Two Dimensional Array

  1. #1
    Join Date
    Jun 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Two Dimensional Array

    I'm having trouble adjusting the output.. here's the code



    Code:
    class TwoDimensionalRequirement
    {
      public static void main(String[] args) 
      {
        String[][] truthTable = new String [4][4];
        String [] header= {"ConditionA", "ConditionB", "And", "Or"};
    
        truthTable[0][0] = "False";
        truthTable[0][1] = "False";
        truthTable[0][2] = "False";
        truthTable[0][3] = "False";
        truthTable[1][0] = "False";
        truthTable[1][1] = "True";
        truthTable[1][2] = "False";
        truthTable[1][3] = "True";
        truthTable[2][0] = "True";
        truthTable[2][1] = "False";
        truthTable[2][2] = "False";
        truthTable[2][3] = "True";
        truthTable[3][0] = "True";
        truthTable[3][1] = "True";
        truthTable[3][2] = "True";
        truthTable[3][3] = "True";
        
        
    	System.out.println(header[0]+"\t"+header[1]+"\t"+header[2]+"\t"+header[3]);
    
        for (int row=0; row<truthTable.length; row++) 
          for (int column=0; column<truthTable[row].length; column++) 
          
            {
           	
           	
         	System.out.print(truthTable[row][column]+"\t\t");
       		
       		}
    	 
          }
          
        }
    how do you make it:




    there's an excess 5th column.. i want it be limited to 4 columns only..
    Last edited by lilyoungfella; 10-12-2008 at 01:50 AM.

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Can you explain the problem again? I don't quite understand what you're asking here.

  3. #3
    Join Date
    Jan 2009
    Location
    Athens, GA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As your code is now. You're having the nested for loops print out each condition followed by two tab characters. What it looks like you want is for it to print out the values of each row on a seperate line.

    HINT: Are you familiar with the println() method? You should be! The code you need is:
    Code:
    System.out.println();
    It does not need to replace anything. And it goes in a specific place. You should be able to figure it out. If not...

Bookmarks

Posting Permissions

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