求帮忙写一个java的小程序,内容如下:
要求用户选择乘法或除法,每个乘法或除法各有10道题,数字是电脑随机给的2个个位数,用户输入答案,如果答对6题则显示“恭喜”如果没有则显示“不及格”谢谢,可以运行的话再附加...
要求用户选择乘法或除法,每个乘法或除法各有10道题,数字是电脑随机给的2个个位数,用户输入答案,如果答对6题则显示“恭喜”如果没有则显示“不及格”谢谢,可以运行的话再附加50
展开
3个回答
展开全部
package cn.com.micc.javatwo; //运行时根据自身情况更改
import java.util.Scanner;
public class AskAnwser {
public static void getMultiple() {
System.out.println("现在进入乘法联系");
int a, b, answer, result;
int count = 0;
for(int i = 0; i < 10; ++i)
{
a =(int)(Math.random() * 10);
b =(int)(Math.random() * 10);
answer = a * b;
System.out.println("a = " + a + ", b = " + b + ", 请输入答案");
Scanner in = new Scanner(System.in);
result = in.nextInt();
if(result == answer)
count++;
}
System.out.println("答题完毕");
if(count >= 6)
System.out.println("恭喜,对了" + count + "题");
else
System.out.println("不及格, 对了" + count + "题");
startPro();
}
public static void getDivide() {
System.out.println("现在进入除法联系");
int a, b, answer1, answer2, result1, result2;
int count = 0;
for(int i = 0; i < 10; ++i)
{
a =(int)(Math.random() * 10);
b =(int)(Math.random() * 10);
answer1 = a / b;
answer2 = a % b;
System.out.println("a = " + a + ", b = " + b + ", 请输入答案商和余数,中间加一个空格,比如(1 2)");
Scanner in = new Scanner(System.in);
result1 = in.nextInt();
result2 = in.nextInt();
if(result1 == answer1 && result2 == answer2)
count++;
}
System.out.println("答题完毕");
if(count >= 6)
System.out.println("恭喜,对了" + count + "题");
else
System.out.println("不及格, 对了" + count + "题");
startPro();
}
public static void startPro() {
int count = 1;
while(count == 1){
System.out.println("请选择您要进行的题目类型(输入1或2):1.乘法 2.除法");
Scanner in = new Scanner(System.in);
int temp = in.nextInt();
if(temp == 1)
getMultiple();
else if(temp == 2)
getDivide();
else {
System.out.println("输入错误");
startPro();
}
}
}
public static void main(String[] args) {
startPro();
}
}
import java.util.Scanner;
public class AskAnwser {
public static void getMultiple() {
System.out.println("现在进入乘法联系");
int a, b, answer, result;
int count = 0;
for(int i = 0; i < 10; ++i)
{
a =(int)(Math.random() * 10);
b =(int)(Math.random() * 10);
answer = a * b;
System.out.println("a = " + a + ", b = " + b + ", 请输入答案");
Scanner in = new Scanner(System.in);
result = in.nextInt();
if(result == answer)
count++;
}
System.out.println("答题完毕");
if(count >= 6)
System.out.println("恭喜,对了" + count + "题");
else
System.out.println("不及格, 对了" + count + "题");
startPro();
}
public static void getDivide() {
System.out.println("现在进入除法联系");
int a, b, answer1, answer2, result1, result2;
int count = 0;
for(int i = 0; i < 10; ++i)
{
a =(int)(Math.random() * 10);
b =(int)(Math.random() * 10);
answer1 = a / b;
answer2 = a % b;
System.out.println("a = " + a + ", b = " + b + ", 请输入答案商和余数,中间加一个空格,比如(1 2)");
Scanner in = new Scanner(System.in);
result1 = in.nextInt();
result2 = in.nextInt();
if(result1 == answer1 && result2 == answer2)
count++;
}
System.out.println("答题完毕");
if(count >= 6)
System.out.println("恭喜,对了" + count + "题");
else
System.out.println("不及格, 对了" + count + "题");
startPro();
}
public static void startPro() {
int count = 1;
while(count == 1){
System.out.println("请选择您要进行的题目类型(输入1或2):1.乘法 2.除法");
Scanner in = new Scanner(System.in);
int temp = in.nextInt();
if(temp == 1)
getMultiple();
else if(temp == 2)
getDivide();
else {
System.out.println("输入错误");
startPro();
}
}
}
public static void main(String[] args) {
startPro();
}
}
展开全部
import java.io.*;
public class C{
public static void main(String args[])throws IOException
{
System.out.println("请选择乘法或者除法\n1、乘法\n其它、除法");
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
String str=bin.readLine();
int score;
if(str.equals("1"))
score=chengfa();
else
score=chufa();
if(score>=6)
System.out.println("恭喜");
else
System.out.println("不及格");
}
static int chengfa()throws IOException
{
int i,j,right=0,count=10;
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
do
{
int result;
i=(int)(Math.random()*10);
j=(int)(Math.random()*10);
System.out.print("第"+(11-count)+"题:"+i+"*"+j+"=");
String str=bin.readLine();
result=Integer.parseInt(str);
if(result==i*j)
{
right++;
}
count--;
}while(count>0);
return right;
}
static int chufa()throws IOException
{
double i,j;
int right=0,count=10;
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
do
{
double result;
i=(int)(Math.random()*10);
j=1+(int)(Math.random()*9);
System.out.print("至少精确到小数点后两位,第"+(11-count)+"题:"+i+"/"+j+"=");
String str=bin.readLine();
result=Double.parseDouble(str);
if(Math.abs(result-i/j)<0.01) right++;
count--;
}while(count>0);
return right;
}
}
//当场给你写了这么多,不给分都对不起我了,当作复习了,楼下的说的对,学语言还是要自己多练,要不然什么都不会的,程序谁都看得懂,自己写的时候就会觉得困难,关键就是多敲键盘,呵呵,加油吧!
public class C{
public static void main(String args[])throws IOException
{
System.out.println("请选择乘法或者除法\n1、乘法\n其它、除法");
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
String str=bin.readLine();
int score;
if(str.equals("1"))
score=chengfa();
else
score=chufa();
if(score>=6)
System.out.println("恭喜");
else
System.out.println("不及格");
}
static int chengfa()throws IOException
{
int i,j,right=0,count=10;
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
do
{
int result;
i=(int)(Math.random()*10);
j=(int)(Math.random()*10);
System.out.print("第"+(11-count)+"题:"+i+"*"+j+"=");
String str=bin.readLine();
result=Integer.parseInt(str);
if(result==i*j)
{
right++;
}
count--;
}while(count>0);
return right;
}
static int chufa()throws IOException
{
double i,j;
int right=0,count=10;
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(br);
do
{
double result;
i=(int)(Math.random()*10);
j=1+(int)(Math.random()*9);
System.out.print("至少精确到小数点后两位,第"+(11-count)+"题:"+i+"/"+j+"=");
String str=bin.readLine();
result=Double.parseDouble(str);
if(Math.abs(result-i/j)<0.01) right++;
count--;
}while(count>0);
return right;
}
}
//当场给你写了这么多,不给分都对不起我了,当作复习了,楼下的说的对,学语言还是要自己多练,要不然什么都不会的,程序谁都看得懂,自己写的时候就会觉得困难,关键就是多敲键盘,呵呵,加油吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
以后提问,是提问如何实现问题,而不是拿别人的源代码。。。不然你是学不到什么东西的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询