Results 1 to 3 of 3
  1. #1
    edwed18 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Help with Scanner

    I am trying to simulate a game of Rock-Scissors-Paper but I get one error from the java compilator. It complains about

    player=input.nextlnt(); but I fail to see what I do wrong. Here is the code for the program:

    Java Code:
    import java.util.*;
    
    public class RockScissorsPaper
    {
    	public static void main(String[]args)
    	{
    	Scanner input = new Scanner(System.in);
    	final int ROCK=0, SCISSORS=1, PAPER=2;
    
    	int player,computer;//human vs computer
    System.out.print("Rock:0; Scissors:1; Paper:2 --Choose:");
    player=input.nextlnt();
    computer=(int)(3*Math.random()) ; //a random number 0,1,2
    System.out.println("The computer chooses"+computer);
    System.out.println("*******************");
    
    if(player==computer)//both choose the same value
    	System.out.print("Itīs a tie");
        else 
    	if(player==ROCK)
     	if(computer==SCISSORS)
    	  System.out.println("Player:rock\nComputer:scissors\nPlayer wins");
    	else		//computer chooses paper
    
    	System.out.println("Player:rock\nComputer: paper\nComputer wins.");
    else		//player chooses scissors or paper
    	if(player==SCISSORS)
    		if(computer==ROCK)
    		System.out.println("Player: scissors\nComputer: rock\nComputer wins.");
    else		//Computer chooses paper
    	System.out.println("Player:scissors\nComputer:paper\nPlayer wins.");
    else		//player chooses paper
    
    if(computer==ROCK)
    System.out.println("Player:paper\nComputer:rock\nPlayer wins.");
    else		//Computer chooses scissors
    	System.out.println("Player:paper\nComputer: scissors\nComputer wins.");
    	}
    }
    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: Help with Scanner

    What is the full error message?
    That will explain what the problem is.

    You need to sort out your indenting, as that code is hard to follow.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    edwed18 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help with Scanner

    Problem solved. The error was that I didnīt use a capital I but l instead in "player=input.nextlnt();". Thanks Tolls.

Similar Threads

  1. Scanner help
    By onions in forum New To Java
    Replies: 1
    Last Post: 04-15-2012, 03:16 PM
  2. Using scanner for CSV
    By getName() in forum Advanced Java
    Replies: 7
    Last Post: 06-20-2010, 05:33 PM
  3. Help With Scanner
    By jtmoney0511 in forum New To Java
    Replies: 10
    Last Post: 10-13-2009, 12:24 AM
  4. Need help with scanner.
    By mainy in forum New To Java
    Replies: 3
    Last Post: 07-28-2009, 03:11 PM
  5. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 02:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •