hej
jeg får en error i min kode : Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "else", delete this token.
Ved ikke hvad jeg gøre forkert ?
- // first allow for input getting
- import javax.swing.*;
- import java.io.*;
-
-
- public class S1P2 {
-
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- // this String will hold the user's input
- String input;
-
- //get input now
- input = JOptionPane.showInputDialog("1 to set password, \n " + "2 to unlock the message");
- // this is the file that will be set and opened
- File file = new File("password.passwrd");
-
- // test for entering or setting the password
- if(input.equals("1")); {
- //setting the password ....
-
- // get the password
- String p = JOptionPane.showInputDialog("Enter the password to set");
-
- //these are two lines we learned about
-
- FileOutputStream outStream = new FileOutputStream(file);
-
- PrintWriter out = new PrintWriter(outStream);
-
- //set the password
- out.println(p);
-
- //close it all
- out.flush();
- out.close();
- outStream.close();
-
-
- }
- // if user wants to test the password
- else FileReader fr = new FileReader(file);
- BufferedReader buffer = new BufferedReader(fr);
-
- //this is the password in the file
- String password = buffer.readLine();
-
- //get the user's attempted password
- String userPass;
- userPass = JOptionPane.showInputDialog("Enter your guess...");
-
- // test the password
- if(password.equals(userPass)){
-
- //if correct
- JOptionPane.showInputDialog(null, CORRECT!!!!");
-
- }
- else {
- // if incorrect:
- JOptionPane.showInputDialog(null, "WRONG = (");
- }
-
-
-
- }
-
- }