DEV Community

Oshi Gupta
Oshi Gupta

Posted on

Java Problem

I am having problem while solving this question in java. Please help me in solving this!!

Question :

Write a java program to print even numbers after odd times jump.
Ex - 2,6,14,26...

2 (then jump 1 even number 4)-6

6 (then jump 3 even numbers 8,10,12)-14

14 (then jump 5 even numbers 16,18,20,22,24)-26

Top comments (1)

Collapse
 
bertilmuth profile image
Bertil Muth • Edited

I donโ€˜t know what you have tried so far. I donโ€˜t want to solve it completely for you, since solving it is important for learning.

But in general, you need to break down a larger problem in smaller problems. Create a method for each subproblem.

For example:
A) You need a method that takes an arbitrary number as input, and jumps an even number (and returns it)
B) You need a method that takes an arbitrary number and jumps an even number n times. Since you have A), you can base your implementation on it.
C) You need some kind of increasing counter, that then uses B) to calculate the next number.

Good luck!