for (k = 1; k <=8 ; k++)
{
rn = (int) ( 0 + Math.random() * 26 );
su = (int) ( 1 + Math.random() * 2);
if (su == 1)
ch = (char) (97 + rn);
else
ch = (char) (65 + rn);
password += ch;
}
When your for loop ends variable k will have value of 9
while (k <= len)
{
rn = (int) (0 + Math.random() * 10 );
password += rn;
k++;
}
Then you run while loop only if k <= len (k is 9 and len is never bigger than 2)
That is why you never enter inside while loop.
Try this instead:
public static void main ( String [] args )
{
int len, k, rn, su;
char ch;
String password = "";
len = (int) (Math.random() * 3 ) ;
for (k = 1; k <=8 ; k++)
{
rn = (int) ( 0 + Math.random() * 26 );
su = (int) ( 1 + Math.random() * 2);
if (su == 1)
ch = (char) (97 + rn);
else
ch = (char) (65 + rn);
password += ch;
}
while (k >= len)
{
rn = (int) (0 + Math.random() * 10 );
password += rn;
k--;
}
System.out.println (password);
}