四则运算及感想
?成員:韓媛媛?宮成榮
? ? ? ?輸出和判斷
? ? ? ? ? ???public?static?int?judge(int?answer){
?????????System.out.println(" ?請(qǐng)輸入您的答案: ?");
????????????Scanner sc2 = new?Scanner(System.in);
????????????int?userResult=sc2.nextInt();
????????????System.out.println(" 正確答案是:"+answer ?);
????????????if(userResult==answer){
????????????????return?0;
????????????}
????????????else?{
????????????????return?1;
????????????}
?二叉樹(shù)的遍歷與排序:
?
??/**定義二叉樹(shù)結(jié)構(gòu)**/
????public?static?class?Node
????{
????????Node leftchild;
????????Node rightchild;
????????int?data;
????????int?result;//各二叉樹(shù)分支之下的四則運(yùn)算結(jié)果
????????
????????Node(int?newData){
????????????leftchild=null;
????????????rightchild=null;
????????????data=newData;
????????????result=data;
????????}
????}
????/**構(gòu)建二叉樹(shù)**/
????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); ???????????
????????}
????}
? /**計(jì)算四則運(yùn)算的值,和括號(hào)內(nèi)每一步運(yùn)算的值 采用遞歸算法** ? ???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("被除數(shù)為零,該算式無(wú)效!");
????????????????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
? ? 結(jié)對(duì)編程的感想:結(jié)對(duì)編程需要互相溝通,一旦有說(shuō)不明白的時(shí)候,需要試著用程序說(shuō)話,準(zhǔn)備時(shí)間過(guò)于倉(cāng)促。多謝學(xué)長(zhǎng)和同學(xué)們的熱心幫忙,總算是弄出了。結(jié)對(duì)編程最好的好處是不會(huì)的可以探討,請(qǐng)教,能學(xué)明白很多東西,這比之前我想不明白,自己想,最后查網(wǎng)絡(luò)要好的多。
?
? ? 由于思路不同,結(jié)對(duì)編程的時(shí)候,有想法不一致,質(zhì)疑,請(qǐng)教同學(xué),最后確定思路后,進(jìn)展速度明顯快了,這也告訴我,下次一定先找好資料,才能加快編碼的效率和質(zhì)量。
? ?
? ?
? 附結(jié)對(duì)編程:地點(diǎn)教室
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/brilliant2016/p/5874249.html
總結(jié)
- 上一篇: 打码平台php源码,正方验证码识别(非打
- 下一篇: 零样本分割系列论文(2)Open-Voc