Exercise 81

179 views
Skip to first unread message

Ethan Gettman

unread,
Mar 5, 2014, 9:07:41 PM3/5/14
to moo...@googlegroups.com
Hello!

So here is my code:  http://paste.mooc.fi/eebd360c

The method createPassword needs to return a string as a password. What I am returning is an ArrayList, which isn't right. Is this the way to go? Is there a way to convert an ArrayList to a String?

This is the output of my code (below). My System.out.print statement works (generates the 13 random characters) but doesn't 'return' them.

And what am I doing wrong in that it's returning the same ArrayList 4 times?

ctvfhhvkoaipwPassword: [c, t, v, f, h, h, v, k, o, a, i, p, w]
Password: [c, t, v, f, h, h, v, k, o, a, i, p, w]
Password: [c, t, v, f, h, h, v, k, o, a, i, p, w]
Password: [c, t, v, f, h, h, v, k, o, a, i, p, w]


Thanks/Kiitos!
Ethan

Kenny Heinonen

unread,
Mar 6, 2014, 5:19:36 AM3/6/14
to moo...@googlegroups.com
Paste has expired but that's ok. You can use String instead of ArrayList because this works:

String town = "Helsin";
town = town + "ki";
System.out.println(town); // Helsinki

So you start with an empty String and build it one character at a time. You know the password length, i.e. how many
times you need to add a new character to your String password. Then you just need a way to randomly pick a character.
For this purpose the first tip in the exercise is pretty important.
Reply all
Reply to author
Forward
0 new messages