四则运算及感想
?成員:韓媛媛?宮成榮
? ? ? ?輸出和判斷
? ? ? ? ? ???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
? ? 結對編程的感想:結對編程需要互相溝通,一旦有說不明白的時候,需要試著用程序說話,準備時間過于倉促。多謝學長和同學們的熱心幫忙,總算是弄出了。結對編程最好的好處是不會的可以探討,請教,能學明白很多東西,這比之前我想不明白,自己想,最后查網絡要好的多。
?
? ? 由于思路不同,結對編程的時候,有想法不一致,質疑,請教同學,最后確定思路后,進展速度明顯快了,這也告訴我,下次一定先找好資料,才能加快編碼的效率和質量。
? ?
? ?
? 附結對編程:地點教室
?
?
轉載于:https://www.cnblogs.com/brilliant2016/p/5874249.html
總結
- 上一篇: 打码平台php源码,正方验证码识别(非打
- 下一篇: 零样本分割系列论文(2)Open-Voc