Hey everyone, I was wondering what is wrong with my code:
import java.util.Scanner; public class PickUpSticks { public static void main(String[] args) { int numberofsticks = 21; System.out.println("Would you like to go first? (Y/N?)"); Scanner user_input = new Scanner(System.in); String goFirst = user_input.nextLine(); Scanner take = new Scanner(System.in); int numbertotake = 0; while (numberofsticks > 0) { if (goFirst.equals("y") || goFirst.equals("Y")); { System.out.println("There are " + numberofsticks + " sticks."); System.out.println("How many sticks will you take? 1 or 2?"); numbertotake = take.nextInt(); numberofsticks = numberofsticks - numbertotake; if (numbertotake > 2) { numbertotake = 2; } else if (numbertotake < 1) { numbertotake = 1; } numberofsticks = numberofsticks - numbertotake; if (numberofsticks<=0) { System.out.println("You lose!"); } else { if ((numberofsticks - 2) % 3 == 0 || numberofsticks - 2 == 0) { numbertotake = 1; } else { numbertotake = 2; } System.out.println("Computer takes " + numbertotake + " sticks."); numberofsticks = numberofsticks - numbertotake; if (numberofsticks <= 0) { System.out.println("You win!"); } } } else { if ((numberofsticks - 2) % 3 == 0 || numberofsticks - 2 == 0) { numbertotake = 1; } else { numbertotake = 2; } System.out.println("Computer takes " + numbertotake + " sticks."); numberofsticks = numberofsticks - numbertotake; if (numberofsticks <= 0) { System.out.println("You win!"); } else { System.out.println("There are " + numberofsticks + " sticks."); System.out.println("How many sticks will you take? 1 or 2?"); numbertotake = take.nextInt(); if (numbertotake > 2) { numbertotake = 2; } else if (numbertotake < 1) { numbertotake = 1; } numberofsticks = numberofsticks - numbertotake; if (numberofsticks <= 0) { System.out.println("You lose!"); } } } } } }
It looks fine to me, but eclipse says that my "else" needs to be removed. However, if I do, the program goes weird. Help please!