You are misinterpreting the scope of the variable inputpassword
and the way you are able to write back values to it. Declared in main, there's no reason to pass inputpassword
(wich is empty, I assume) to your readpassword()
method. Instead you should read the password from inside the method and return the result.
you'd better do something like this:
public static String readPassword()
{
String passwordReadResult;
// read the password from wherever it comes, e.g. console
// ...
return passwordReadResult;
}
Update:
I think in your case you don't want do pass inputpassword
to your readPassword
method (there are cases where this makes sense, but i don't want to add confusion here).
You pass something to a method if it needs this data to operate on it. If you have inputpassword
declared outside, then it doesn't yet contain a password. So passing it to readpassword
makes no sense because readpassword
doesn't need an empty password variable! It can read the password let's say from the console but it doesn't need inputpassword
for this. If the method is done reading the password, the it return it's value via the return
statement. To get your password to be stored into inputpassword
in main you do s.t. like this:
String inputpassword = readPassword();