Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2008, 04:11 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
[SOLVED] Need help with Loops...please!
Hey thanks for your time. Can you please help me with my program. Originally this code asks the user to input a password until he/she gets it correct. But I am suppose to change the code to make it where the user gets only 3 tries to get it correct. Can somebody please help me and tell me what I am suppose to do. Thanks!

import java.util.Scanner;
class Example3 {
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
String password = "";
while(!(password.equals("branes")))
{
System.out.println("What is the password");
password = scan.nextLine();
}
System.out.println("Welcome!");
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-09-2008, 04:16 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Sorry about this guys I have already figured this one out...thanks anyways! Mods you can close this if you want.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 05:29 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Hey Zebra, fancy posting your solution just incase it helps others in the future?
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 06:01 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
BLUE= Change to whatever you want

Code:
import java.util.Scanner; class Loop1 { public static void main (String[] args) { int count = 1; Scanner scan = new Scanner(System.in); String password = ""; boolean foundpassword = false; while(count <= 3) { System.out.println("What is the password"); password = scan.nextLine(); if(password.equals("Zebra is cool")) { count = 4; foundpassword = true; } else { count = count + 1; } } if(foundpassword == true) { System.out.println("Welcome!"); } else { System.out.println("Sorry...you failed!"); } } }

Last edited by DonCash : 04-09-2008 at 06:18 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 06:19 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Nice one!

I have done it for you this time but in future please add the [code] [ /code] tags around your code. It makes it much easier to reads and avoids errors.
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 03:44 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Ok no problem. Thanks!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help with Slope (Loops) Zebra New To Java 9 04-18-2008 05:39 AM
Question about loops BHCluster New To Java 4 04-16-2008 07:40 PM
Loops (while do etc) manupr New To Java 1 01-15-2008 05:59 AM
Nested loops? gabriel New To Java 4 08-06-2007 06:51 PM
Help me: loops in java silvia New To Java 3 07-19-2007 08:47 PM


All times are GMT +3. The time now is 01:07 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org