Trouble with For loop and variables in a program
Im relatively new to java, and as part of a course that i am on, need to write an application to validate a password entered by a user.
A while ago, i had my program at least semi working, but now i have done something, and it doesnt, lol.
I was wondering if anyone could identify any problems with my for loop, and subsequent code?
System.out.println("Please enter your username...");
getUsername = EasyIn.getString();
System.out.println("Welcome " + getUsername + "!");
System.out.println("Please enter your password for validation...");
getPassword = EasyIn.getString();
getLength = getPassword.length();
System.out.println("Password length = " + getLength);
System.out.println("Password is fine");
// loops over string and reports back numbers of letters
for (int i = 0; i < getLength; i++)
System.out.println("Letter " + i);
System.out.println(" = " + c);
boolean start = true;
// Checks for space
boolean b_space = Character.isWhitespace(c);
if (b_space == true)
System.out.println("You have a space in your password, please remove it and try again");
//start = false;
while(b_space == true);
if (b_space == false)
System.out.println("Password has no spaces");
The easyIn class is something that i was provided with to get input from users. The main problem seems to be that the loop prints the "password has no spaces" bit for as many times at the length of the password. The loop is mainly supposed to count the letters in the password, so, if a password was fish, letter 0 would be f, letter 1 would be i and so on.
if someone could tell me where im going wrong, i would very much appreciate it, im going mad!