Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Array: Divide current element in loop by previous element

807599Apr 7 2007 — edited Apr 9 2007
Hello,

I am going crazy with a simple issue on Arrays. I have spent hours on this (beginner!) I am trying to have an array and divide the second element by the first, the third by the second, the fourth by the third....

In other words,
int [] test = {a, b, c, d};   //Using letters for illustrative purposes
//desired code is "divide b by a, c by b, d by c...
========================
My code looks like this:
public class ArrayTest {

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
		int[] stock = {1,2,5,8};
		
		
		for(int x : stock) {
			
			System.out.println("This is the element value:" + x);
			
			for(int i = 0; i < 5 ; i++) {
				int y = stock[i + 1] / stock;
System.out.println(y);

}

}



}
}



If anyone could help me or guide me to the right resources.

Thanks,
SymDev
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2007
Added on Apr 7 2007
2 comments
367 views