• 四则运算及感想


     成员:韩媛媛 宫成荣

           输出和判断

               

      public static int judge(int answer){

             System.out.println("  请输入您的答案:  ");

                Scanner sc2 = new Scanner(System.in);

                int userResult=sc2.nextInt();

                System.out.println(" 正确答案是:"+answer  );

                if(userResult==answer){

                    return 0;

                }

                else {

                    return 1;

                }

     二叉树的遍历与排序:

      /**定义二叉树结构**/

        public static class Node

        {

            Node leftchild;

            Node rightchild;

            int data;

            int result;//各二叉树分支之下的四则运算结果

            

            Node(int newData){

                leftchild=null;

                rightchild=null;

                data=newData;

                result=data;

            }

        }

        /**构建二叉树**/

        public static void creatBinTree(int array[],LinkedList<Node> nodeList){

            

            for(int parentIndex=0;parentIndex<array.length/2-1;parentIndex++){

                nodeList.get(parentIndex).leftchild = nodeList.get(parentIndex * 2 + 1);

                nodeList.get(parentIndex).rightchild = nodeList.get(parentIndex * 2 + 2);            

            }

        }

     
     
    /**计算四则运算的值,和括号内每一步运算的值 采用递归算法**
       

      public static void values(Node node){

            if (node.leftchild== null) {

                 return;

            }

            values(node.leftchild);

            values(node.rightchild);

            if(node.data==0){

                node.result=node.leftchild.result+node.rightchild.result;

                }

            else if(node.data==1){

                node.result=node.leftchild.result-node.rightchild.result;

            }

            else if(node.data==2){

                node.result=node.leftchild.result*node.rightchild.result;

            }

            else 

            {

                if(node.rightchild.result==0){

                    System.out.println("被除数为零,该算式无效!");

                    return;

                }

                node.result=node.leftchild.result/node.rightchild.result;

            }

        }

    }

    程序地址:https://git.coding.net/brilliant/The-two-weekend-yunsuan.git

                 git@git.coding.net:brilliant/The-two-weekend-yunsuan.git

        结对编程的感想:结对编程需要互相沟通,一旦有说不明白的时候,需要试着用程序说话,准备时间过于仓促。多谢学长和同学们的热心帮忙,总算是弄出了。结对编程最好的好处是不会的可以探讨,请教,能学明白很多东西,这比之前我想不明白,自己想,最后查网络要好的多。

        由于思路不同,结对编程的时候,有想法不一致,质疑,请教同学,最后确定思路后,进展速度明显快了,这也告诉我,下次一定先找好资料,才能加快编码的效率和质量。

       

       

      附结对编程:地点教室

  • 相关阅读:
    ESP8266 A0的使用
    电脑总是被乱装各种软件怎么办?那就设置一个密码吧!
    笔记本光驱位改装固态系统硬盘教程
    任务管理器无法呼出
    Python stomp 介绍与代码
    Power(x,y)
    旋转图像
    字符串相乘
    缺失的正数
    外观数列
  • 原文地址:https://www.cnblogs.com/brilliant2016/p/5874249.html
Copyright © 2020-2023  润新知