Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Problems with Loop Structure

  1. #1
    Junior Member Sean137's Avatar
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problems with Loop Structure

    import java.util.*;
    import java.lang.*;
    /**
     * To output whether a students password is valid or not.
     * 
     * @author (Sean)
     * @version (December 13, 2010)
     */
    class SemesterProject
    {
        public static void main(String[]args)throws Exception
        {
            Scanner scanReader = new Scanner(System.in);
            String password = "";
            int length;
            int passwordLength;
            int minimumCharacters = 12;
            int maximumCharacters = 25;
            int countCaps = 0;
            int countLowerCase = 0;
            int numbers = 0;
            int specialCharacters = 0;
     
                System.out.println("This was made by Sean");
                System.out.print("Please enter a password to be checked for validity:  ");
                    password = scanReader.nextLine ();
                    passwordLength = password.length ();
     
            try
                        {
     
                            if (passwordLength == 12)
                            { 
                                System.out.println("Your pasword meets the length requirments");
                            }
                            else
                            {
                                throw new Exception ();
                            }
                        }
                        catch (Exception ex)
                        {
                            System.out.println("Please Re-enter a valid password:  ");
                            password = scanReader.nextLine ();
                        }
            }
    }

    I need my program to tell whether the password meets the requirements (12 characters). Ive gotten it to print the request for in put and when it is inputed with a 12 character word it says it meets the requirements. When the incorrect amount of charactersis input it says to reenter a valid amount of characters. But then it wont reiterate after a new one is input. Could someone please help?

    Thanks
    Sean137


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Problems with Loop Structure

    You don't have any loops in there at all.

    Hint: You want to do something while a certain criteria is not met, right?

  3. #3
    Junior Member Sean137's Avatar
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Re: Problems with Loop Structure

    OH ......MY.......GOSH!!!!!

    Thank YOU soooooooo much!!!

    Ive been doing this for about 3 months now so I am kinda new.

    ThankYou
    Sean

  4. #4
    Junior Member
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problems with Loop Structure

     
    import java.util.Scanner;
     
    class SemesterProject {
    	public static void main(String[]args) {
    		Scanner scanReader = new Scanner(System.in);
    		String password = "";
    		int length;
    		int passwordLength;
    		int minimumCharacters = 12;
    		int maximumCharacters = 25;
    		int countCaps = 0;
    		int countLowerCase = 0;
    		int numbers = 0;
    		int specialCharacters = 0;
     
    		System.out.println("This was made by jesamjasam, not Sean ;)");
    		System.out.print("Please enter a password to be checked for validity:  ");
    		password = scanReader.nextLine ();
    		passwordLength = password.length ();
    		while (passwordLength != 12) {
    			System.out.println("Please Re-enter a valid password:  ");
    			password = scanReader.nextLine ();
    			passwordLength = password.length ();
    		}
    		System.out.println("Your pasword meets the length requirments");
    	}
    }

  5. #5
    Junior Member Sean137's Avatar
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problems with Loop Structure

    ok... I have one more question. How do you then take the same input word with the 12 characters and make sure that there are 3 and only 3 uppercase letters.

    Thanks
    Sean

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Problems with Loop Structure

    Quote Originally Posted by jesamjasam View Post
     
    import java.util.Scanner;
     
    class SemesterProject {
    	public static void main(String[]args) {
    		Scanner scanReader = new Scanner(System.in);
    		String password = "";
    		int length;
    		int passwordLength;
    		int minimumCharacters = 12;
    		int maximumCharacters = 25;
    		int countCaps = 0;
    		int countLowerCase = 0;
    		int numbers = 0;
    		int specialCharacters = 0;
     
    		System.out.println("This was made by jesamjasam, not Sean ;)");
    		System.out.print("Please enter a password to be checked for validity:  ");
    		password = scanReader.nextLine ();
    		passwordLength = password.length ();
    		while (passwordLength != 12) {
    			System.out.println("Please Re-enter a valid password:  ");
    			password = scanReader.nextLine ();
    			passwordLength = password.length ();
    		}
    		System.out.println("Your pasword meets the length requirments");
    	}
    }
    Sigh. Spoonfeeding is bad enough. Spoonfeeding an answer that isn't as good as one already given is just pointless.

    Why?

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Problems with Loop Structure

    Quote Originally Posted by Sean137 View Post
    ok... I have one more question. How do you then take the same input word with the 12 characters and make sure that there are 3 and only 3 uppercase letters.

    Thanks
    Sean
    Take a look at the String and Character APIs for useful functions. I'd suggest you break this up into more than one method: write one method that checks length, another that checks content, etc.

    String (Java Platform SE 6)
    Character (Java Platform SE 6)

  8. #8
    Junior Member
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Problems with Loop Structure

    Quote Originally Posted by KevinWorkman View Post
    Sigh. Spoonfeeding is bad enough. Spoonfeeding an answer that isn't as good as one already given is just pointless.

    Why?
    sorry didn't see you already answered that one

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Problems with Loop Structure

    Quote Originally Posted by jesamjasam View Post
    sorry didn't see you already answered that one
    Even had I not, spoonfeeding is still not helping. Especially when you don't even give out a great solution.

Similar Threads

  1. What is the fastest and most memory-efficient data structure?
    By aussiemcgr in forum Collections and Generics
    Replies: 5
    Last Post: October 11th, 2012, 03:48 PM
  2. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  3. Data Structure for ordered binay tree
    By wash in forum Algorithms & Recursion
    Replies: 0
    Last Post: April 23rd, 2010, 05:31 PM
  4. problems with loop in Java App
    By dmonx in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 04:13 PM
  5. .xls data structure
    By helloworld922 in forum JDBC & Databases
    Replies: 3
    Last Post: August 20th, 2009, 07:12 PM