I can only print string literals
I'm writing a class to make a random password, but for some reason I can only print string literals in the main method. Can anyone tell me why?
Code:
public class RandomPassword
{
/* main method, only used for testing methods */
public static void main(String[] args)
{
System.out.print(RandomPassword.fixLast("this_"));
}
/* returns random char alpha (caps or no caps) or underscore '_'
*this will temporrily return char 'a', waiting for ***'s method */
public static char randomChar()
{
return 'a';
}
/*fixLast, this will test to make sure that the last character of password is not '_'
*if it is it will replace the last character with a random char (by calling randomChar) */
public static String fixLast(String pass)
{
//isolates the last char of the password
char lastChar = (pass.charAt(pass.length()-1));
//test if lastChar meets the required range.
while(('a' <= lastChar && 'z' >= lastChar) || ('A' <=lastChar && 90 >= 'Z'))
{
pass = pass.substring(0, pass.length()-1) + RandomPassword.randomChar();
lastChar = (pass.charAt(pass.length()-1));
}
return pass;
}
}