This program was posted earlier and I thought I had it figured out, so I thanked everyone and thought that was it. But... I am still having a problem...
The below program is supposed to take input for integer value "n" and then output an iteration from 1 to n where each digit in the sequence is multiplied by -2 and then summed. So, if I enter 3 the output should be: 1, -2, 4...and the sum would be 3. The trouble is that right now if I enter 3, I only get 1, -2 and if I enter any number between 4 and 15 I only get 1, -2, 4, -8. I know that I am missing something simple, I just don't know what. Can someone please tell me what I'm doing wrong?
CODE
int n;
// ======
System.out.println("This program will take input for the value n");
System.out.println("and output the sequence.");
System.out.println("=======================================");
// ==============================================================
Scanner scannerObject = new Scanner(System.in);
// ===============================================
System.out.println("Please input an integer: ");
n = scannerObject.nextInt();
System.out.println("Integer entered = " +n);
// ==========================================
int ii;
int formula = 1 *-2;
for(ii = 1;ii <= n;ii = formula * ii++)
{
System.out.println(ii);
}
I really want to learn something here, and put this behind me! So please reply soon? Thanks.