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
What I have so far:
My output: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]); } } }
index = 0,element =5
index = 1,element =10
index = 2,element =15
index = 3,element =20
index = 4,element =25
ETC.