Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

public class tester { int[]alpha= {25,35,45,55}; for(int x= 0; x<=4; x++) System.out.print(alpha[x]+" "); } How can I make it compile?

OpenStudy (anonymous):

first of all you need to have main method secondly in loop you should stop at element 4, e.g. make x<4 instead of x<=4 because it would be out of bounds

OpenStudy (anonymous):

How do you write the main method if alpha was already declared?

OpenStudy (anonymous):

I have absolutely no understanding of arrays :(

OpenStudy (anonymous):

wrap evetyhing to main method

OpenStudy (anonymous):

you always have to have main method arrays have nothing to do with it

OpenStudy (anonymous):

public class tester { public static void main (String[] args) { int[]alpha= {25,35,45,55}; for(int x= 0; x<4; x++) System.out.print(alpha[x]+" "); } }

OpenStudy (anonymous):

OH NO DUH!!!

OpenStudy (anonymous):

Thank you so much! I was thinking of object oriented programming and I was really confused

OpenStudy (anonymous):

Remove the equal sign from for loop of array, as they are zero-index based. It'll always count a index more than your actual array indexes,if you put equal.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!