I have two other classes but they are very small, and this is where the error lies. This is my code:

import java.util.Scanner;

public class Player
{

	private boolean isHuman;
	private int score=0;
	private Scanner input;
	

	public Player(int human)
	{
		System.out.println("If you would like to play, press 1. Otherwise, press 0 to have two computers play against each other.");
		human = input.nextInt();
		if (human>0)
			isHuman=true;
		else
			isHuman=false;

	}

	public int declare()
	{
		int throw;
	
		if(isHuman=true)
		{
			input = new Scanner(System.in);
			
			System.out.println("What would you like to throw? Enter either 1 or 2.");
			throw = input.nextInt();
			System.out.println("You threw a " + throw);
		}
		else
		{
			double t;

			t = (double) Math.random();
			throw = (int) (t+1.5);
			System.out.println("The computer threw a " + throw);
		}
		
		return throw;
	}
	

	public void deposit(int amount)
	{
		score = score + amount;
	}

	public void withdraw(int amount)
	{
		score = score - amount;
	}

	public int score()
	{
		return score;
	}

I am getting the following message when I try to compile it:

./Player.java:24: not a statement
                int throw;
                ^
./Player.java:24: ';' expected
                int throw;
                   ^
./Player.java:24: illegal start of expression
                int throw;
                         ^
./Player.java:31: illegal start of expression
                        throw = input.nextInt();
                              ^
./Player.java:32: illegal start of expression
                        System.out.println("You threw a " + throw);
                                                            ^
./Player.java:32: ';' expected
                        System.out.println("You threw a " + throw);
                                                                 ^
./Player.java:39: illegal start of expression
                        throw = (int) (t+1.5);
                              ^
./Player.java:40: illegal start of expression
                        System.out.println("The computer threw a " + throw);
                                                                     ^
./Player.java:40: ';' expected
                        System.out.println("The computer threw a " + throw);
                                                                          ^
./Player.java:43: illegal start of expression
                return throw;
                       ^
10 errors

As far as I can tell, it is not recognizing the variable "throw". I have tried declaring it in the beginning of the class, in the method declare(), have tried every variation of the words private/public int throw; , and nothing seems to work. I just need the declare() method to return the value for throw. What should I do?

Please be very specific and explicit, since I am very new to JAVA, just started using it 3 weeks ago, and don't know much...if anything lol. THANK YOU!

I am aware that I cut off the last bracket of the class, I just forgot to paste it.

Member Avatar for r.stiltskin

throw is a reserved word. You can't use it as a variable name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.