1 Public classTrangleproblem {2 3 Static intRes=1;4 intCodepart=1;5 intn=100;6Stack<param> stack=NewStack<param>();7 Public Static voidMain (string[] args) {8Trangleproblem tb=NewTrangleproblem ();9 while(Tb.solve () = =false)Ten ; One } A - Public BooleanSolve () - { the - - Switch(Codepart) - { + Case1:stack.push (NewParam (N, 6)); -codepart=2; + Break; A Case2: at if(Stack.peek (). nn==1) -Codepart=5; - Else -Codepart=3; - Break; - Case3:stack.push (NewParam (Stack.peek (). nn-1, 4)); incodepart=2; - Break; to Case4:res+=Stack.peek (). nn; +Codepart=5; - Break; the Case5:codepart=Stack.peek (). ReturnAddress; * Stack.pop (); $ Break;Panax Notoginseng Case6: - return true; the + A } the return false; + } - $ } $ classParam - { - intnn; the intReturnAddress; -Param (intNnintreturnaddress)Wuyi { the This. nn=nn; - This. returnaddress=ReturnAddress; Wu } -}
Trangleproble Switch Method java