How do you return to a previous method in java?
-
import java.util.Scanner; import java.util.*; public class CombPerm { public static void main( String[] args) { // declare any necessary constants, variables, // or objects boolean bDebugSW = false; Scanner scan = new Scanner(System.in); String Scmmand = ""; final String SENT = "quit"; // read in a command if(scan.hasNextLine()) { Scmmand = scan.nextLine(); System.out.println(Scmmand); } else { System.out.println("Quitting"); System.exit(0); } // it will run until sentinel ("quit") is found while(!Scmmand.equals(SENT)) { // call appropriate method. selection(scan, Scmmand, bDebugSW); // Read in a command // end of sentinel loop } System.out.println("Reached Quit. Exiting."); // end of main method } // start selection method public static void selection(Scanner scan, String Scmmand, boolean bDebugSW) { // declare any necessary contants, variables, or objects String temp = ""; int r = 0; int n = 0; if(scan.hasNextInt()) { r = scan.nextInt(); System.out.println(r); } else { if(scan.hasNext()) { temp = scan.next(); System.out.println(temp); System.out.println("Input is not an Integer, Quitting now."); System.exit(0); } } // Read in number of selections (r) // Note: // the number of selections (r) must be greater than 0 if(scan.hasNextInt()) { n = scan.nextInt(); System.out.println(n); } else { System.out.println("Input is not an Integer, Quitting now."); System.exit(0); } // Read in number of choices (n) // Note: // the number of choices (n) must be greater or equal to // the number of selections (r). if( n<r) { System.out.println("N must be greater than or equal to R"); System.exit(0); } // figure out which math function is needed to perform if(!Scmmand.equals("combination") && !Scmmand.equals("permutation")) { System.out.println("Input not combination nor permutation."); System.out.println("Qutting now."); System.exit(0); } int factR = 0; factR = factorial(r, bDebugSW); int factN = 0; factN = factorial(n, bDebugSW); int ansC = 0; int ansP = 0; if(Scmmand.equals("combination")) { System.out.println("comb"); ansC = ((factN)/((factR)*factorial((n-r), bDebugSW))); System.out.println("ansC = " +ansC); return; } if(Scmmand.equals("permuation")) { System.out.println("perm"); ansP = ((factN)/(factorial((r-n), bDebugSW))); System.out.println(ansP); return; } // end of selection method } // start factorial method public static int factorial(int iNum, boolean bDebugSW) { // declare any necessary variables int result = 1; // if 0, then 0! = 1 if(iNum == 0) { System.out.println("fact=0!=1"); return result; } else { System.out.println("factfalse " +iNum); } // if anything else, then do normal factorial calculation // Hint: // use "for loop" to find factorial int i = 1; for(i = iNum; i >= 1; i--) { System.out.println("result"); result = result * i; System.out.println(result); } // return result System.out.println(result+"........"); return result; } } // end of factorial method // end of CombPerm class
-
Answer:
cant get u
Punitha J at Yahoo! Answers Visit the source
Other answers
cant get u
Punitha J
Related Q & A:
- Why cannot we use static keyword inside a method in java?Best solution by Stack Overflow
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
- How to Get Main output into Common() method in Java?Best solution by pages.cs.wisc.edu
- How can I retrieve my contacts that I had with a previous yahoo account?Best solution by answers.yahoo.com
- How to ask a previous employer to rehire you?Best solution by forbes.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.