title: A time limit for user input
body: <p>I am having some problems making a small game for myself. The piece of code I am having problems with is a timeout for user input. For example: The game will show a letter on the screen. The user has to enter that letter by a certain time; if they don't, they take damage.  If someone could explain what I could use to fix this problem it would be great.</p>
  
  <pre><code>package weapons;
  
  import java.util.Random;
  import java.util.Scanner;
  
  
  class wepons {
      public static void main(String args[]){
  
          int weapondamage =0 , health = 0 , hits = 0, potion = 0, beast = 0, beastdmg = 0, letter = 0;
          String weapon;
          ;
  
          Scanner in = new Scanner (System.in);   
  
          System.out.println ("please pick a wepon that will kill the boss \n");
          weapon = in.nextLine().toLowerCase();
          if (weapon.equals("sword")){
            System.out.println("you have picked the sword");
            weapondamage = (int) ((Math.random()*100));
            health = weapondamage*3;
          }
  
  
          System.out.println("Sword damage is " + weapondamage);
          System.out.println("Boss health is " + health);
          System.out.println("Enter the amount of hits it will take to kill the boss.");
          hits = in.nextInt();
          if(hits == health/weapondamage) {
          System.out.println("you have killed the boss.The boss had droped a potion.\nYou pick up the potion and drink it!\nYour health has now gone up to 350hp");
          }
  
          else {
  
              System.out.print("You have failed to kill the boss");
  
  
  
          }
          potion = (int)350;
          beastdmg = (int) ((Math.random()*60));
          System.out.println("By killing the boss you have awoken the beast!");
          System.out.println("The beast nocks you onto your back");
          System.out.println("The beast will hit you for"+beastdmg+"damage");
          System.out.println("You can block the beast damage by hitting the write key");
          Random r = new Random();
          int c = r.nextInt(26) + (byte)'a';
          System.out.println((char)c);
          letter = in.next().charAt(0);
          if(  letter == ((char)c)){
              System.out.println("You blocked the beast damage");
  
  
  
  
          }
          else {
  
              System.out.print("You took damage");
  
  
  
          }
          }
  
  
  
  
          }  // main
  </code></pre>