Forums - Open Redstone Engineers
Question about my java program (Sorry xeo D:) - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: Question about my java program (Sorry xeo D:) (/thread-494.html)

Pages: 1 2 3 4


Question about my java program (Sorry xeo D:) - David - 07-03-2013

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:

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 Tongue)


RE: Question about my java program (Sorry xeo D:) - qwerasd205 - 07-03-2013

I would try using
Code:
public static String[][] screen = new String[6][5];
i think that it is messed up slightly in JAVA so that X goes -1


RE: Question about my java program (Sorry xeo D:) - David - 07-03-2013

(07-03-2013, 07:33 PM)qwerasd205 Wrote: I would try using
Code:
public static String[][] screen = new String[6][5];
i think that it is messed up slightly in JAVA so that X goes -1

OK, got it working! Ty.


RE: Question about my java program (Sorry xeo D:) - Xeomorpher - 07-03-2013

Now. Burn java.


RE: Question about my java program (Sorry xeo D:) - David - 07-03-2013

(07-03-2013, 07:38 PM)Xeomorpher Wrote: Now. Burn java.

I'm wondering xeo, how many angry e-mails have you sent to oracle? Be honest.


RE: Question about my java program (Sorry xeo D:) - VirtualPineapple - 07-03-2013

David, why Java ;n;


RE: Question about my java program (Sorry xeo D:) - David - 07-03-2013

(07-03-2013, 07:50 PM)VirtualPineapple Wrote: David, why Java ;n;

I'm *kinda* new to programming, besides batch (Which isn't really a programming language) I don't know any language, and Java is an easier to learn language (I think). So I will be movin' to C or C++ or something


RE: Question about my java program (Sorry xeo D:) - seankingman - 07-03-2013

You should try BASIC; or if you want a starter launguage, try Python.


RE: Question about my java program (Sorry xeo D:) - David - 07-03-2013

(07-03-2013, 08:22 PM)seankingman Wrote: You should try BASIC; or if you want a starter launguage, try Python.

I know a tiny, tiny, TINY bit of basic. Pyton , naaah. Isnt that a scripting language?


RE: Question about my java program (Sorry xeo D:) - seankingman - 07-03-2013

I also only know a tiny bit of BASIC and a little bit of VB and C++. As for Python, consult Xeo.