Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Loop in java to give only certain amount of tries problem

$
0
0
this is my code. i wanted it to see if the password the user enters is correct. it supposed to give them 5 tries and when the user puts in the right password it doesn't continue to do the loop 5 times. why wont it stop when the person gets it right.
import java.io.*;
import java.util.Scanner
public class loop
{
  public static void main(String[] args)
  {
    String word;
    Scanner toy = new Scanner (System.in);
    int count;    
    count = 0; 
    while (count < 5)
    {
      System.out.println(" Enter Password to enter Security System");
      word = toy.next();
      if ((word.equals("Disney")))
      {
        System.out.print("YAY!");
      }
      else 
      {
        System.out.println(" too bad try again ") ;
      }
      count = count + 1;
    }
    System.out.println("SWEET JOB");
  }
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>