码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2016-03-19 21:06:42      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

/**
*
* @author Zhangtingfei
*/
//package 张庭飞;

import java.util.Random;

import org.junit.Test;

public class Sizeyunsuan {

public static void main(String[] args) {
calculate(20);

}
/*
* 随机生成题函数,参数amount为出题数量
*/
@Test
public static void calculate(int amount)
{
Random r = new Random();
for(int x=0;x<amount;x++)
{

int symbol = r.nextInt(4);
int front = r.nextInt(100);
int last = r.nextInt(100);
char sym =‘+‘;
switch(symbol)
{
case 0:sym=‘-‘;break;
case 1:sym=‘x‘;break;
case 2:sym=‘/‘;break;
case 3:break;
}
if(front>=last)
{
System.out.println(front+""+sym+last);
}
else
{
System.out.println(last+""+sym+front);
}

}
}

}

四则运算

标签:

原文地址:http://www.cnblogs.com/zhangtingfei/p/5296110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!