zoukankan      html  css  js  c++  java
  • 软件工程个人作业02

     

     这周老师加了括号余数分数等。难度进一步的提升,挑战越来越大。

    设计思路:在原有的代码上进行处理,新建一个类来实现括号的处理,还要添加上负数等;

    代码:

    1 package test;
      2 import java.lang.*;
      3 import java.util.*;
      4 
      5 public class test {
      6     /*public static   void zhenfenshu(Shu A){
      7         if(A.a/A.d>1||A.b/A.e>1)
      8         {
      9             A.shu();
     10         }
     11     }*/
     12     public static Boolean chachong1(Shu x,Shu y){
     13         if(x.a/x.d==y.a/y.d&&x.b/x.e==y.b/y.e&&x.c==y.c)
     14         {
     15             return true;
     16         }
     17         else if(x.a/x.d==y.d/y.e&&x.b/x.e==y.a/y.d&&x.c==y.c)
     18         {
     19             return true;
     20         }
     21         else{return false;}
     22     }
     23 
     24     public static void main(String args[]){
     25         int i;
     26         System.out.println("请输入要输出的题数:");
     27         Scanner num=new Scanner(System.in);
     28         int n = num.nextInt();
     29         Shu s[]=new Shu [n];    
     30             for(i=0;i<n;i++){
     31                 s[i]=new Shu();
     32                 boolean ss=true;
     33                 //zhenfenshu(s[i]);
     34                 while(ss){
     35                     ss=false;
     36                     s[i].shu();
     37                     for(int j=0;j<i;j++){
     38                         if(chachong1(s[i],s[j])){
     39                             ss=true;
     40                         }
     41                     }
     42                 }
     43             }
     44             for(i=0;i<n;i++)
     45             {
     46                 s[i].show();
     47             }
     48             }
     49 }
     50 class Shu{
     51     int a,b,c,d,e;
     52     int s1,s2,s3,s4;
     53     public  void shu(){
     54         a = (int)(Math.random()*100);
     55         d = (int)(Math.random()*100);
     56         e = (int)(Math.random()*100);
     57         b = (int)(Math.random()*100);
     58         c = (int)(Math.random()*3);
     59     }
     60     public void show(int a2,int a3){
     61         if(a2==1&&a3==1){
     62             daifuhao();
     63             int m1=0,m2=0;
     64             this.suiji(m1,m2);
     65             m1=(int)(Math.random()*(n-1));
     66             m2=(int)(Math.random()*(n-1)+2);
     67             while(m2<m1+2){
     68                 m2=(int)(Math.random()*(n-1)+2);
     69             }
     70             for(int i=0;i<m1;i++){
     71                 System.out.print(a[i]+zhuan(f[i]));
     72             }
     73             System.out.print("(");
     74             for(int i=m1;i<m2-1;i++){
     75                 System.out.print(a[i]+zhuan(f[i]));
     76             }
     77             System.out.print(a[m2-1]);
     78             System.out.print(")");
     79             if(m2-1<n-1)System.out.print(zhuan(f[m2-1]));
     80             for(int i=m2;i<n-1;i++){
     81                 System.out.print(a[i]+zhuan(f[i]));
     82             }
     83             if(m2!=n)System.out.print(a[n-1]);
     84         }
     85         else if(a2==1&&a3==2){
     86             daifuhao();
     87             for(int i=0;i<n-1;i++){
     88                 System.out.print(a[i]+zhuan(f[i]));
     89             }
     90             System.out.print(a[n-1]);
     91         }
     92         else if(a2==2&&a3==1){
     93             int m1=0,m2=0;
     94             this.suiji(m1,m2);
     95             m1=(int)(Math.random()*(n-1));
     96             m2=(int)(Math.random()*(n-1)+2);
     97             while(m2<m1+2){
     98                 m2=(int)(Math.random()*(n-1)+2);
     99             }
    100             for(int i=0;i<m1;i++){
    101                 System.out.print(a[i]+zhuan(f[i]));
    102             }
    103             System.out.print("(");
    104             for(int i=m1;i<m2-1;i++){
    105                 System.out.print(a[i]+zhuan(f[i]));
    106             }
    107             System.out.print(a[m2-1]);
    108             System.out.print(")");
    109             if(m2-1<n-1)System.out.print(zhuan(f[m2-1]));
    110             for(int i=m2;i<n-1;i++){
    111                 System.out.print(a[i]+zhuan(f[i]));
    112             }
    113             if(m2!=n)System.out.print(a[n-1]);
    114         }
    115         else{
    116             for(int i=0;i<n-1;i++){
    117                 System.out.print(a[i]+zhuan(f[i]));
    118             }
    119             System.out.print(a[n-1]);
    120         }
    121         System.out.println("=");
    122     }    
    123 }

    。总结:还是不太清楚括号的运用,需要多加练习

  • 相关阅读:
    angularjs的$on、$emit、$broadcast
    angularjs中的路由介绍详解 ui-route(转)
    ionic入门教程-ionic路由详解(state、route、resolve)(转)
    Cocos Creator 加载使用protobuf第三方库,因为加载顺序报错
    Cocos Creator 计时器错误 cc.Scheduler: Illegal target which doesn't have uuid or instanceId.
    Cocos Creator 构造函数传参警告 Can not instantiate CCClass 'Test' with arguments.
    Cocos Creator 对象池NodePool
    Cocos Creator 坐标系 (convertToWorldSpaceAR、convertToNodeSpaceAR)
    Cocos Creator 常驻节点addPersistRootNode
    Cocos Creator 配合Tiled地图的使用
  • 原文地址:https://www.cnblogs.com/zeminzhang/p/6527946.html
Copyright © 2011-2022 走看看