1 import java.util.*;
2 import java.math.*;
3 public class timu {
4 public static void main(String[] args) {
5 int i;
6 int a,c,d,sum,j=0;
7 int []b=new int [20];
8 int []e=new int [20];
9 String []fuhao={"+","-"};
10
11 while (true)
12 {
13 a=2;
14 sum=0;
15 for (i=0;i<a;i++) {
16 b[i]=(int)(Math.random()*100); //0~99
17 }
18 for (i=0;i<a;i++) {
19 c=(int)(Math.random()*2); // 随机生成fuhao数组 的下标 即0到2
20 System.out.printf("%d",Math.abs(b[i]));
21 if((fuhao[c]=="+")&&(i!=a-1)){
22 System.out.printf("+");
23 }
24 else if ((fuhao[c]=="-")&&(i!=a-1)){
25 System.out.printf("-");
26 b[i+1]=b[i+1]*(-1);
27 }
28 }System.out.printf("=");
29 for (i=0;i<a;i++)
30 {
31 sum=sum+b[i];
32 }
33 Scanner in=new Scanner(System.in);
34 d=in.nextInt();
35 if(sum==d)
36 {
37 System.out.printf("回答正确!\n");
38 }
39 else if(d==-1) {
40 System.out.printf("谢谢使用!");
41 break;}
42 else{
43 System.out.printf("回答错误!\n");
44 System.out.printf("正确答案:%d\n",sum);
45 continue;}
46 }
47 }
48 }
1 import java.io.*;
2 import java.util.*;
3 public class Factorial {
4 public static void main(String[]args){
5 while (true){
6 int a,i,j=1;
7 int answer;
8 a=(int)(Math.random()*11);
9 System.out.printf("%d!=",a);
10 Scanner in=new Scanner(System.in);
11 for(i=1;i<=a;i++)
12 j*=i;
13 answer=in.nextInt();
14 if (answer==j){
15 System.out.printf("回答正确!\n");
16 }
17 else if(answer==-1) {
18 System.out.printf("谢谢使用!");
19 break;}
20 else{
21 System.out.printf("回答错误!\n");
22 System.out.printf("正确答案:%d\n",j);
23 continue;}
24 }
25 }
26 }
1 import java.awt.EventQueue;
2 import javax.swing.JFrame;
3 import java.awt.FlowLayout;
4 import javax.swing.JTextField;
5 import javax.swing.JButton;
6 import javax.swing.JLabel;
7 public class jiemian {
8
9 private JFrame frame;
10 private JTextField textField;
11 private JTextField textField_1;
12 public static void main(String[] args) {
13 EventQueue.invokeLater(new Runnable() {
14 public void run() {
15 try {
16 jiemian window = new jiemian();
17 window.frame.setVisible(true);
18 } catch (Exception e) {
19 e.printStackTrace();
20 }
21 }
22 });
23 }
24
25 public jiemian() {
26 initialize();
27 }
28 private void initialize() {
29 frame = new JFrame();
30 frame.setTitle("\u51FA\u9898\u7CFB\u7EDF");
31 frame.setBounds(100, 100, 450, 300);
32 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33 frame.getContentPane().setLayout(null);
34
35 JButton btnNewButton = new JButton("\u5F00\u59CB\u7B54\u9898");
36 btnNewButton.setBounds(332, 10, 93, 30);
37 frame.getContentPane().add(btnNewButton);
38
39 textField = new JTextField();
40 textField.setBounds(10, 10, 314, 241);
41 frame.getContentPane().add(textField);
42 textField.setColumns(10);
43
44 textField_1 = new JTextField();
45 textField_1.setBounds(332, 55, 93, 35);
46 frame.getContentPane().add(textField_1);
47 textField_1.setColumns(10);
48 }
49 }
总结:
(1)感觉还有很多的不足,例如,不懂把生成的题目放到界面中的文本框里面。
(2)java的知识掌握得还不够好,书上的知识还需要多花时间去看看。
(3)在这个结对编程的过程中,我做了生成题目和阶乘,对友做了主界面,感觉都需要好好努力(⊙0⊙),真的真的要花时间去看去想去做。。