
-----------------------------------
Shivu
Sat Apr 19, 2008 9:52 pm

ARRAYS!!- Shift Down...
-----------------------------------
hi! we started learning arrays about a week ago and now i'm stuck in this problem. I've been working on it for four hours now and i can't seem to figure out the logic. I've been working on it on paper, like tracing through the diagrams, but I still can't find out the answer. Here is the question:

ShiftDown.java:  Write a program that asks user to input 20 integers and stores them in an array.  It then shifts the content of the array down by 2 (elements at the bottom will wrap around to go to the top) 
An example of shifting an array of size 5 down by 2:
	
45          A ONE ARRAY)

10    A [0]
12    A [1]
45    A [2]
23    A [3]
16    A [4]

If someone can please help me, i'll be grateful :D  and also, if you can EXPLAIN it to me that'd be great! 

thanks!

-----------------------------------
Shivu
Sat Apr 19, 2008 10:22 pm

Re: ARRAYS!!- Shift Down...
-----------------------------------
one thing to add on.... it should be able to work with only one array declared and no if statements and i think only 2 variables.. (this is what one i was told)- but obviously i'm not able to figure it out..

-----------------------------------
syntax_error
Sat Apr 19, 2008 11:22 pm

RE:ARRAYS!!- Shift Down...
-----------------------------------
here a concept: use a temp variable to hold one value in then shift that value 2 down then place temp in the spot that you shifted and so forth.

Also showing some code to show what you are trying would be nice to see ;)

P.S. dont forget code tags

-----------------------------------
Shivu
Sat Apr 19, 2008 11:33 pm

Re: RE:ARRAYS!!- Shift Down...
-----------------------------------

import java.util.*;

public class ShiftDown
{
	public static void main (String [] args) 
	{
	Scanner sc = new Scanner (System.in);
	
	final int MAX = 5;
	int [] num = new int [MAX];
	
	for (int i =0; i 