A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
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?
 2 years ago
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?

This Question is Closed

Tomas.A
 2 years ago
Best ResponseYou've already chosen the best response.2first 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

myteethhurt
 2 years ago
Best ResponseYou've already chosen the best response.0How do you write the main method if alpha was already declared?

myteethhurt
 2 years ago
Best ResponseYou've already chosen the best response.0I have absolutely no understanding of arrays :(

Tomas.A
 2 years ago
Best ResponseYou've already chosen the best response.2wrap evetyhing to main method

Tomas.A
 2 years ago
Best ResponseYou've already chosen the best response.2you always have to have main method arrays have nothing to do with it

Tomas.A
 2 years ago
Best ResponseYou've already chosen the best response.2public 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]+" "); } }

myteethhurt
 2 years ago
Best ResponseYou've already chosen the best response.0Thank you so much! I was thinking of object oriented programming and I was really confused

Neeraj_OCW
 2 years ago
Best ResponseYou've already chosen the best response.0Remove the equal sign from for loop of array, as they are zeroindex based. It'll always count a index more than your actual array indexes,if you put equal.
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.