LinkedList<String> list = new LinkedList<>(); int max = 3; int min = 0; int range = max - min + 1; int score = 0; list.add("Player 1: "); list.add("Player 2: "); list.add("Player 3: "); list.add("Player 4: "); list.add("Player 5: "); for (int i = 0; i < list.size(); i++) { int att = (int)(Math.random() * range) + min; if (att == 3) { System.out.println(list.get(i) + att); score = att; score++; if (score == 3) { int nextscore = score + att; System.out.println(list.get(i) + nextscore); } } if (att <= 2) { System.out.println(list.get(i) + att); } }
Player 1: 3 //The random attempt shot is 3 but the score didn't added for the second attempt. Player 2: 2 Player 3: 1 Player 4: 1 Player 5: 2
if (att == 3) { System.out.println(list.get(i) + att); score = att; // So score is now equal to 3 score++; // ***score is now equal to 4 if (score == 3) { // this test will always fail int nextscore = score + att; System.out.println(list.get(i) + nextscore); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)