我稍微改了改自己再改改吧import java.io.*;
import javax.swing.*;
import java.util.*;public class Mini {
Vector questions = new Vector();
Vector answers = new Vector();
public void questions() {
String record1 = null;
try {
FileReader fr = new FileReader("questions.txt");
BufferedReader br = new BufferedReader(fr);
record1 = new String();
while((record1 = br.readLine())!=null) {
questions.addElement(record1);
}
br.close();
fr.close();
} catch (IOException e) {
System.err.println("got an error!");
e.printStackTrace();
}
} public void answer() {
String record2 = null;
try {
FileReader fr = new FileReader("answers.txt");
BufferedReader br = new BufferedReader(fr);
record2 = new String();
while((record2 = br.readLine())!=null) {
answers.addElement(record2);
}
br.close();
fr.close();
} catch (IOException e) {
System.err.println("got an error!");
e.printStackTrace();
}
} void begin()
{
for ( int i = 0; i< questions.size();i++)
{
String result = JOptionPane.showInputDialog(questions.elementAt(i));
if (result.compareToIgnoreCase((String)answers.elementAt(i))== 0)
{
result = "good";
} else {
result = "sorry";
}
JOptionPane.showMessageDialog(null,
result,"Are you right?",JOptionPane.INFORMATION_MESSAGE);
}
} public static void main(String args[]) {
Mini mi=new Mini();
mi.questions();
mi.answer();
int judge = 0;
while(true)
{
String result = JOptionPane.showInputDialog("Enter -1 to quit");
try {
judge = Integer.parseInt(result);
} catch (NumberFormatException e) { }
if (judge == -1) break;
mi.begin();
}
System.exit(0);
}
}
import javax.swing.*;
import java.util.*;public class Mini {
Vector questions = new Vector();
Vector answers = new Vector();
public void questions() {
String record1 = null;
try {
FileReader fr = new FileReader("questions.txt");
BufferedReader br = new BufferedReader(fr);
record1 = new String();
while((record1 = br.readLine())!=null) {
questions.addElement(record1);
}
br.close();
fr.close();
} catch (IOException e) {
System.err.println("got an error!");
e.printStackTrace();
}
} public void answer() {
String record2 = null;
try {
FileReader fr = new FileReader("answers.txt");
BufferedReader br = new BufferedReader(fr);
record2 = new String();
while((record2 = br.readLine())!=null) {
answers.addElement(record2);
}
br.close();
fr.close();
} catch (IOException e) {
System.err.println("got an error!");
e.printStackTrace();
}
} void begin()
{
for ( int i = 0; i< questions.size();i++)
{
String result = JOptionPane.showInputDialog(questions.elementAt(i));
if (result.compareToIgnoreCase((String)answers.elementAt(i))== 0)
{
result = "good";
} else {
result = "sorry";
}
JOptionPane.showMessageDialog(null,
result,"Are you right?",JOptionPane.INFORMATION_MESSAGE);
}
} public static void main(String args[]) {
Mini mi=new Mini();
mi.questions();
mi.answer();
int judge = 0;
while(true)
{
String result = JOptionPane.showInputDialog("Enter -1 to quit");
try {
judge = Integer.parseInt(result);
} catch (NumberFormatException e) { }
if (judge == -1) break;
mi.begin();
}
System.exit(0);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货