I cant seem to figure this out, its probably something really easy that I'm over looking but its annoying me now.
When someone types in "commands" they have to push the enter key twice before it will out print what its supposed to.
Heres a snippet of my code:
if (cmd.equals("commands")) { for (int i = 0; i < commands.length; i++) System.out.println("Current commands: " + commands[0][i] + commands[1][i]); }
Heres the whole class:
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { private BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); private String[][] commands = {{"newpassword", "listpasswords"}, {" - Saves the password you type", " - Shows a list of saved passwords."}}; public static void main(String[] args) throws IOException { Main m = new Main(); while (true) { System.out.println("Please type 'commands' to view a list of available commands, " + "\nor just type in a command."); m.getInput(m.input.readLine()); } } public void getInput(String cmd) throws IOException { String password = input.readLine(); if (cmd.equals("commands")) { for (int i = 0; i < commands.length; i++) System.out.println("Current commands: " + commands[0][i] + commands[1][i]); } if (cmd.equals("newpassword")) { writeToFile(password); System.out.println("You typed" + password); } } public void writeToFile(String toWrite) throws IOException { FileWriter fstream = new FileWriter("password/file.txt"); BufferedWriter out = new BufferedWriter(fstream); out.write(toWrite); out.close(); System.out.println("Wrote " + toWrite +" to file."); } }