Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

myteethhurt

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
  • 2 years ago

  • This Question is Closed
  1. Tomas.A
    Best Response
    You've already chosen the best response.
    Medals 2

    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

    • 2 years ago
  2. myteethhurt
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  3. myteethhurt
    Best Response
    You've already chosen the best response.
    Medals 0

    I have absolutely no understanding of arrays :(

    • 2 years ago
  4. Tomas.A
    Best Response
    You've already chosen the best response.
    Medals 2

    wrap evetyhing to main method

    • 2 years ago
  5. Tomas.A
    Best Response
    You've already chosen the best response.
    Medals 2

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

    • 2 years ago
  6. Tomas.A
    Best Response
    You've already chosen the best response.
    Medals 2

    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]+" "); } }

    • 2 years ago
  7. myteethhurt
    Best Response
    You've already chosen the best response.
    Medals 0

    OH NO DUH!!!

    • 2 years ago
  8. myteethhurt
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  9. Neeraj_OCW
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
    • Attachments:

See more questions >>>

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.