(Java) Help with alternating negative and positive numbers.

Hello coders, I'm new to this forum and especially new to programming.

But my program objective is to display an array of 200 integers, with the numbers(element) starting at 5, increasing by 5, and negate the even numbers. For instance: 5, -10, 15, -20 and so on.

I'm having problems negating and displaying the negative numbers :(

I believe I'm suppose to use modulus, but I have no clue how :confused:

What I have so far:

Code :

public class Arrays2 {
public static void main(String [ ] commandlineArguments){
//Declare & Instatiate an Array of 200 integers
Integer[ ] arrayOf200Integers = new Integer[200];
//initialize the array
Integer powersOf2 = new Integer(5);
for(int i=0;i<arrayOf200Integers.length;i++){
arrayOf200Integers[i] = powersOf2;
//add again by 5
powersOf2 = powersOf2 + 5;
}
//Display Array
Integer numerator = new Integer(0);
for(int i=0;i<arrayOf200Integers.length;i++){
numerator = i;
System.out.println("index = " +numerator + "," + "element =" + arrayOf200Integers[i]);
}
}
}

My output:

index = 0,element =5

index = 1,element =10

index = 2,element =15

index = 3,element =20

index = 4,element =25

ETC.

Re: (Java) Help with alternating negative and positive numbers.

Re: (Java) Help with alternating negative and positive numbers.

sam965: Please don't provide solutions. Please read this info for new forum users.

Re: (Java) Help with alternating negative and positive numbers.

Before inserting any integer to arrayOf200Integers check whether it is an even number or not, if it's an even number then change it sign to negative and then add it to arrayOf200Integers.