1. Member
Join Date
Feb 2012
Posts
1
Rep Power
0

I am taking ap java in high school. We have a project.

I cant figure this out help me out please!

Problem:
For each multiple of 10 in the given array change all the values following it to be that multiple of 10, untill encountering another mulltiple of 10.

Example: 2,10,3,4,20,5 becomes 2,10,10,10,20,20
..........: 10,1,20,2 becomes 10,10,20,20

i have;

public static int[] multsOfTen(int[] nums)
{

for(int i=0;i<nums.length;i++)
{
if(nums[i]%10==0)
{

}
}
}

Since you return an array you should build a new array as you go through the loop. You have three possible outcomes. The first is when no power of 10 is reached (either skip this value or add it to the new array, and the second case is if a power of 10 is encountered. From here on you do two things at each step, check the next value if an array, if it is not a multiple of 10, replace it with the current multiple of 10, otherwise store the new multiple of 10 and repeat. No one here is going to give you code for this. While this description may be a bit confusing, try to understand it and apply it. Some psudo code

Java Code:
```declare current multiple
for
if (condition)
if (condition)
add multiple of 10 to array
end if
if (condition)
continue on or put value into new array
end if
end if
if (condition)
save current multiple of 10