1 Replies - 134 Views - Last Post: 15 January 2013 - 04:38 PM Rate Topic: -----

#1 tastycoffee1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 14-January 13

Loop in java to give only certain amount of tries problem

Posted 15 January 2013 - 04:21 PM

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");
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Loop in java to give only certain amount of tries problem

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9094
  • View blog
  • Posts: 34,147
  • Joined: 12-June 08

Re: Loop in java to give only certain amount of tries problem

Posted 15 January 2013 - 04:38 PM

Do not create duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1