Problems with Loop Structure
Code Java:
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?:confused:
Thanks
Sean137
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?
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
Re: Problems with Loop Structure
Code java:
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");
}
}
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:confused:
Re: Problems with Loop Structure
Quote:
Originally Posted by
jesamjasam
Code java:
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?
Re: Problems with Loop Structure
Quote:
Originally Posted by
Sean137
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:confused:
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)
Re: Problems with Loop Structure
Quote:
Originally Posted by
KevinWorkman
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 :o
Re: Problems with Loop Structure
Quote:
Originally Posted by
jesamjasam
sorry didn't see you already answered that one :o
Even had I not, spoonfeeding is still not helping. Especially when you don't even give out a great solution.