Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     import java.io.*;
  2.     import java.util.ArrayList;
  3.     import java.util.List;
  4.     import java.util.Scanner;
  5.     import javax.swing.JOptionPane;
  6.    
  7.         public class Test {
  8.         public static void main(String[] args) throws InterruptedException {
  9.  
  10.         // Location of file to read
  11.         File file = new File("a.txt");
  12.         List<String> lines = new ArrayList<String>();
  13.  
  14.         try {
  15.  
  16.             Scanner scanner = new Scanner(file);
  17.  
  18.             while (scanner.hasNextLine()) {
  19.                 lines.add(scanner.nextLine());
  20.             }
  21.             scanner.close();
  22.             for (int i=1 ; i < lines.size(); i+=2)
  23.             {
  24.                 String question = lines.get(i - 1);
  25.                 String answer=lines.get(i += 1);
  26.                 String a = JOptionPane.showInputDialog("" + question);
  27.                 if (a.equals(answer)){
  28.                     Thread.sleep(10000);
  29.                 }else
  30.                     JOptionPane.showMessageDialog(null,"Please look it up");
  31.             }
  32.         } catch (FileNotFoundException e) {
  33.          System.out.println("Can't find file");  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement