Josephus Problem | ( Iterative Solution ) | Iterative solution for Josephus Problem ; Method for finding the winning child . ; For finding out the removed chairs in each iteration ; Driver Program to test above method
class Test { private int josephus ( int n , int k ) { int sum = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { sum = ( sum + k ) % i ; } return sum + 1 ; } public static void main ( String [ ] args ) { int n = 14 ; int k = 2 ; Test obj = new Test ( ) ; System . out . println ( obj . josephus ( n , k ) ) ; } }