package chuti;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.FileNotFoundException;
class Counter
{
private int a;
private int b;
public int add(int a,int b)
{
return a+b;
}
public int reduce(int a,int b)
{
return a-b;
}
public int multiplication(int a,int b)
{
return a*b;
}
public int division(int a,int b)
{
if(b!=0)
return a/b;
else return 0;
}
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.FileNotFoundException;
class Counter
{
private int a;
private int b;
public int add(int a,int b)
{
return a+b;
}
public int reduce(int a,int b)
{
return a-b;
}
public int multiplication(int a,int b)
{
return a*b;
}
public int division(int a,int b)
{
if(b!=0)
return a/b;
else return 0;
}
}
public class Demo {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Counter counter=new Counter();
PrintWriter out = null;
try {
out = new PrintWriter("text.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int sum = 0;
Counter counter=new Counter();
PrintWriter out = null;
try {
out = new PrintWriter("text.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int sum = 0;
for (int i = 1; i <=10; i++) {
int a = (int) Math.round(Math.random() * 100);
int b = (int) Math.round(Math.random() * 100);
int m= (int) Math.round(Math.random() * 3);
switch(m)
{
case 0:
System.out.println(i+": "+a+"/"+b+"=");
while(b==0){ b = (int) Math.round(Math.random() * 100); }
int c0 = in.nextInt();
out.println(a+"/"+b+"="+c0);
if (c0 == counter.division(a, b)) {
sum += 10;
System.out.println("恭喜答案正确");
}
else {
System.out.println("抱歉,答案错误");
}
break;
case 1:
System.out.println(i+": "+a+"*"+b+"=");
int c = in.nextInt();
out.println(a+"*"+b+"="+c);
if (c == counter.multiplication(a, b)) {
sum += 10;
System.out.println("恭喜答案正确");
}
else {
System.out.println("抱歉,答案错误");
}
break;
case 2:
System.out.println(i+": "+a+"+"+b+"=");
int c1 = in.nextInt();
out.println(a+"+"+b+"="+c1);
if (c1 == counter.add(a, b)) {
sum += 10;
System.out.println("恭喜答案正确");
}
else {
System.out.println("抱歉,答案错误");
}
break ;
case 3:
System.out.println(i+": "+a+"-"+b+"=");
int c2 = in.nextInt();
out.println(a+"-"+b+"="+c2);
if (c2 == counter.reduce(a, b)) {
sum += 10;
System.out.println("恭喜答案正确");
}
else {
System.out.println("抱歉,答案错误");
}
break ;
}
}
System.out.println("成绩"+sum);
out.println("成绩:"+sum);
out.close();
}
}
}
System.out.println("成绩"+sum);
out.println("成绩:"+sum);
out.close();
}
}
这是一个出一个解答一个题,然后判断结束后再出下一个题,一共出30个题的代码。
记得,后面还有一个web