Write the code using java: The Josephus Problem is a famous mathematical puzzle
ID: 3536867 • Letter: W
Question
Write the code using java: The Josephus Problem is a famous mathematical puzzle that goes back to ancient times. There are many stories to go with the puzzle. One is that Josephus was one of a group of Jews who were about to be captured by the Romans. Rather than be enslaved, they chose to commit suicide. They arranged themselves in a circle and, starting at a certain person, started counting off around the circle. Every nth person had to leave the circle and commit suicide. Josephus decided he didnExplanation / Answer
import java.util.Scanner; public class JosephusProblem { public static void main(String[] args) { Scanner input = new Scanner(System.in); int safespace; System.out.println("Please enter the number of soliders"); int soldiers = input.nextInt(); System.out.println("Please enter the how many soldiers are skipped before the next death"); int count = input.nextInt(); //safespace = 1 + (((soldiers-1) * count) % soldiers); safespace = 1 + (((count-1) * soldiers) %count); System.out.println("The safe place to stand would be " + safespace); } //end main } //end class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.