So the other day I thought I might go ahead and try to make a few simple programs to see if anything I have done is soaking in. I did a few math ones, which were easy enough, but then I tried to do a password program. It was easy enough to write, but the thing is I could only do it with numbers. Although thats alright, I was aiming to do one with Strings rather than ints. Thing is I have no idea how to take the input of a String like an int would (readInt). Heres my short password program involving just ints if it helps any:
package OtherStuff; import acm.program.ConsoleProgram; import java.util.*; public class stringPassword extends ConsoleProgram { public void run() { int password = 2256; while (true) { int input = readInt("Enter a password: "); if (input == password) { println("Password accepted"); break; } if (input != password) { println("Password not accepted\n"); } } } }
So all in all, how can I take the input of a String and use it in the same way I use ints in the code above?