Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How do you start at a certain point in an array?

$
0
0
So i had some questions about a particular part of my java assignment.

How would I create a method that would start at a particular point in an array along with continuing an algorithm of that start value for the remaining slots?

like lets say..

I have an array that is length 10.
and i have a start value of int 5.

I want to start at position 5 in the array and then cause that
start value to square itself, and then move through the remaining slots of the array squaring the next values within that same array.

so the output should look something like this:


0 0 0 0 0 25 36 49 64 81

This is what I have so far, which isn't much but i'm stuck.
Also, for my assignment, we are expected to write this method recursively, how would i go about starting that?


        public static int[] squares(int[] array, int startIndex)
        {
          int startIndex = 5;
	  squares = new squares[10];
	  
	  
	  if(startindex < squares)
	  {  
		 for(int i = 0; i < squares.length; i++)
		 {
		   //empty, I need help with this part
		 }
	  {
	  else
	  {
	    return squares;
	  }
        }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>