> Write a method called upByThrees, which prints the first n numbers in this sequence in a column.?

Write a method called upByThrees, which prints the first n numbers in this sequence in a column.?

Posted at: 2014-12-18 
A little reflection ought to show you that n numbers in this

sequence will end in the sum (n - 1)*3 + 1. Thus the first 3 numbers

will end 1, 4, 7, and 7 is (3 - 1)*3 + 1. The first 7 end in 19. So your for

loop runs (k = 1; k <= (1 + 3*(n-1)); k +=3)

>

> John (gnujohn)

Consider the sequence 1, 4, 7, 10, 13. The sequence starts at 1, and adds 3 to get the next value. Write a method called upByThrees, which prints the first n numbers in this sequence in a column.

For example, upByThrees(4) should print:

1

4

7

10

I've written this code:

public void upByThrees(int n) {

for (int k = 1; k < n; k+=3)

System.out.println(k);

}

but obviously it doesn't work because it's only printing the numbers less than n. I'm not sure how to make it print the first n numbers in the sequence. any help would be greatly appreciated!