Skip to content

Instantly share code, notes, and snippets.

@sjdhanasekaran
Last active July 5, 2018 12:38
Show Gist options
  • Save sjdhanasekaran/13aa521bf06c1f93d2af9e63d907709e to your computer and use it in GitHub Desktop.
Save sjdhanasekaran/13aa521bf06c1f93d2af9e63d907709e to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class JosephusProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of Persons : ");
int i=sc.nextInt();
String s = Integer.toBinaryString(i);
String s1 = s.substring(1) +s.charAt(0);
int output = Integer.parseInt(s1, 2);
System.out.println(output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment