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?
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
How do you write the main method if alpha was already declared?
I have absolutely no understanding of arrays :(
wrap evetyhing to main method
you always have to have main method arrays have nothing to do with it
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]+" "); } }
OH NO DUH!!!
Thank you so much! I was thinking of object oriented programming and I was really confused
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.
Join our real-time social learning platform and learn together with your friends!