07-03-2013, 07:25 PM 
	
	
	
		Hello I am kinda new to java, I've been messing around with it a lil for the past few weeks.
Now I created this program that would print out a 5x5 square using an 2d String array.
Here is my code:
The problem is that I'm getting this output:
Which is a 4x5 square and not a 5x5 one. Can someone tell me what the problem is?
(Xeo, please do not say that the problem is java itself )
)
	
	
	
	
Now I created this program that would print out a 5x5 square using an 2d String array.
Here is my code:
Code:
package main;
public class Main {
    
    //Creating an 2D array of strings.
    
    public static String[][] screen = new String[5][5];
    
    public static void main(String[] args) {
        
        //Setting the array using some fancy for loops.
        
        for(int i = 0; i < 5; i++)
            for(int j = 0; j < 5; j++)
                screen[i][j] = j + ", " + i;
        
        //Printing the array using some fancy for loops.
        for(int i = 0; i < 5; i++)
        {
            for(int j = 0; j < 5; j++)
            {
                if(j == 4)
                {
                    System.out.println("");
                }
                else
                {
                    System.out.print(screen[i][j] + " | ");
                }
            }
        }
    }
}The problem is that I'm getting this output:
Code:
0, 0 | 1, 0 | 2, 0 | 3, 0 | 
0, 1 | 1, 1 | 2, 1 | 3, 1 | 
0, 2 | 1, 2 | 2, 2 | 3, 2 | 
0, 3 | 1, 3 | 2, 3 | 3, 3 | 
0, 4 | 1, 4 | 2, 4 | 3, 4 |Which is a 4x5 square and not a 5x5 one. Can someone tell me what the problem is?
(Xeo, please do not say that the problem is java itself
 )
)
	 



 
			 
			

 omething
omething
	
