Hey,
I am writing a program that asks you if you would like to save or load passwords to a file, then it runs the specific routine. Here is the code:
import java.util.Scanner; import java.io.*; public class Passwords { public static void main(String[] arg) throws IOException { String[] passwords = new String[10]; int place; String pass; String sl; //the variable that figures out whether you're going to save or load passwords Scanner scan = new Scanner(System.in); System.out.print("Would you like to save or load passwords?"); sl = scan.nextLine(); switch (sl.toLowerCase()) { case "save": save(passwords); } case "load": load(passwords); } static void save (String[] passwords) throws IOException { passwords = new String[10]; int place = 0; String pass; Scanner scan = new Scanner(System.in); while (place<10) { System.out.print("?"); pass = scan.nextLine(); passwords[place] = pass; place++; if (pass == null) { break; } } FileWriter saveFile = new FileWriter("passwords.txt"); place = 0; while (place<10) { saveFile.write(passwords[place] + "\n"); place++; } saveFile.close(); } static void load(String[] passwords) throws IOException { int place = 0; BufferedReader saveFile = new BufferedReader(new FileReader("passwords.txt")); System.out.print("Your passwords are: "); while (place<10) { passwords[place] = saveFile.readLine(); System.out.print(passwords[place]); place++; } } }
My problem is that in the main() routine of the program, in the switch, at the load routine, it has both "load" and load(passwords) are underlined. It tells me that I cannot convert fron string to boolean, and that the expression must return a value. It is obvious that all of the routines are void, so I am not sure what to do.
Help?
-Silent