Results 1 to 6 of 6
- 04-09-2008, 02:11 PM #1
[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!");
}
}
- 04-09-2008, 02:16 PM #2
Sorry about this guys I have already figured this one out...thanks anyways! Mods you can close this if you want.
- 04-09-2008, 03:29 PM #3
Hey Zebra, fancy posting your solution just incase it helps others in the future?
Did this post help you? Please
me! :cool:
- 04-09-2008, 04:01 PM #4
BLUE= Change to whatever you want
Java 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("[COLOR="Navy"]Zebra is cool[/COLOR]")) { count = 4; foundpassword = true; } else { count = count + 1; } } if(foundpassword == true) { System.out.println("[COLOR="Navy"]Welcome![/COLOR]"); } else { System.out.println("[COLOR="Navy"]Sorry...you failed![/COLOR]"); } } }Last edited by DonCash; 04-09-2008 at 04:18 PM.
- 04-09-2008, 04:19 PM #5
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
me! :cool:
- 04-10-2008, 01:44 PM #6
Similar Threads
-
[SOLVED] Need help with Slope (Loops)
By Zebra in forum New To JavaReplies: 9Last Post: 04-18-2008, 03:39 AM -
Question about loops
By BHCluster in forum New To JavaReplies: 4Last Post: 04-16-2008, 05:40 PM -
Loops (while do etc)
By manupr in forum New To JavaReplies: 1Last Post: 01-15-2008, 03:59 AM -
Nested loops?
By gabriel in forum New To JavaReplies: 4Last Post: 08-06-2007, 04:51 PM -
Help me: loops in java
By silvia in forum New To JavaReplies: 3Last Post: 07-19-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks