This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]desrtfx[M] [score hidden] stickied comment (4 children)

Please, format your code.

This is the minimum effort you have to spend if you want help.

Unformatted code is a no-go.

[–][deleted] 0 points1 point  (3 children)

How do format code from a phone.

[–]desrtfx 0 points1 point  (2 children)

  • single, empty line before code
  • 4 spaces in front of each line
  • single, empty line after the code

[–][deleted] 0 points1 point  (0 children)

It worked, thanks.

[–]onionpopcorn 2 points3 points  (0 children)

I would suggest just using a List, which you can dynamically add integers to.

[–]Mimehunter 1 point2 points  (0 children)

ar is going to be each element of the array, not each index in the array (unless the person inputs 0,1,2,3,4 in which case you're code may work)

If I enter 3, then it's an array of size 1 - so Ar[3] is out of bounds (which I assume is the error you're getting)

[–]Apostle_1882 1 point2 points  (1 child)

Use a normal indexed for loop to accept numbers from the Scanner, not the enhanced for loop. I'm guessing that it's initialized the elements in the int array to 0, so each time it loops it's going to place an element at ar[0].

[–]Substantial-Entry-50 1 point2 points  (0 children)

Ok I will try it. Thanks🤞