功能:实现真分数的四则运算

语言:Java  平台:JDK下的eclipse

github地址:https://github.com/yeershao/hello-world/commit/9920a987de88fdf878cc2a2e404b405fa96485ea

代码:

public class Computting

{

private String getPfQuestion() {
//说明:getPfQuestion()得到真分数题目函数,随机生成真分数题目,返回真分数题目字符串。
int t = 0;
String strz = "";

int x1=1+(int)(Math.random()*10);
int x2=1+(int)(Math.random()*10);//分母

int y1=1+(int)(Math.random()*10);
int y2=1+(int)(Math.random()*10);//分母

if( x2 <= x1 ){
t = x2;
x2 = x1;
x1 = t;
if( x1 == x2 ) {
x1 = x1 - 1;//保证分子比分母小
}
}

if( y2 <= y1 ){
t = y2;
y2 = y1;
y1 = t;
if( y1 == y2 ) {
y1 = y1 - 1;//保证分子比分母小
}
}

int z=1+(int)(Math.random()*100);

if( z<=25 ) {
strz = "×";
}
if( z>25 && z<=50 ) {
strz = "÷";
if( y1 == 0 )
y1 = y1 + 1;//除数的分子不能为0是不是
}
if( z>50 && z<=75) {
strz = "+";
}
if( z>75 ) {
strz = "-";
if( x1/x2 > y1/y2 ) {

t = x1;
x1 = y1;
y1 = t;

t = x2;
x2 = y2;
y2 = t;//保证减法是大数减去小数
}
}

String strx1 = String.valueOf( x1 );
String strx2 = String.valueOf( x2 );
String stry1 = String.valueOf( y1 );
String stry2 = String.valueOf( y2 );

String ques = " " + strx1 + "/" + strx2 + strz + stry1 + "/" + stry2 + "=";

return ques;
}//getPfQuestion

public static void main(String args[])
{
Computting com=new Computting();
Scanner scanner=new Scanner(System.in);
a:
String str=com.getPfQuestion();
System.out.println(str);
double d=scanner.nextDouble();

System.out.println("Continue?");
int c=scanner.nextChar();
if(c=='y')
goto a:
}
}

最新文章

  1. MVC之权限管理-网站开发之路
  2. PHP memory_get_usage()管理内存
  3. Sublime Text快捷键和常用插件推荐
  4. case when then else end
  5. php 使用 restler 框架构建 restfull api
  6. C# RSA和Java RSA互通
  7. ASP.NET MVC 4 (一)路径映射
  8. C#多线程交替赋值取值
  9. Spring 数据源配置一:单一数据源
  10. vsftp关于&quot;550 create directory operation failed&quot;问题解决
  11. ubuntu cenots 禁止本地登陆
  12. 一个2D平面游戏,的碰撞引擎实现
  13. 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解 (旧版本 | 仅作参考)
  14. DES加解密
  15. 19 款仿 Bootstrap 后台管理主题免费下载
  16. Spark Java API 计算 Levenshtein 距离
  17. QTP自动化测试
  18. 剑指offer--5.用两个栈实现队列
  19. webpack的使用二
  20. SQL注入之Sqli-labs系列第十九关(基于头部的Referer POST报错注入)

热门文章

  1. VueJs大全;vee-validate(一个验证vue插件), bootstrap-vue, axios简介。
  2. You Don&#39;t Know JS: this &amp; Object Prototypes( 第5章 Prototypes)
  3. [转载]mapreduce合并小文件成sequencefile
  4. linux基础知识(1)
  5. 轮播,试用与微信公众号,apicloud苹果安卓
  6. vue给元素动态添加class
  7. pytorch backward问题
  8. Ubuntu中php.ini修改运行内存
  9. Leetcode 980. 不同路径 III
  10. 连续三月涨势明显,PostgreSQL 将崛起?