DEV Community

loading...

Java Problem

Oshi Gupta
Tech enthusiast GitHub profile : https://github.com/oshi36
・1 min read

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

Discussion (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!