java - Strange Run Time Error -


The following code works fine but as soon as I start any integer input, it goes into the infinite loop. I need an integer value for testing.

  import java.io. *; Import java.util. *; Import java.text *; Import java.math. *; Import java.util.regex *; Class test class {public static zero master throws exception [scanner] {scanner stdin = new Scanner (System.in); // Here I just input into an AN / INT digit like intact T = stdin.nextInt (); Long calculation = 0; String str = stdin.nextLine (); Four [] c = str.toCharArray (); ('A': Case 'I': Case 'O': Case 'U' (at j = 0; j and lt; strength (); J ++) {switch (c [j]): calculation + +; Default: break;}} arrangement (calculation, str.length ());} public static zero system (long V, long en) {long total = fact (n); long time together = ((combination V)) * (Fact (N-1)) * 2); Long Answer = (Total - Together); If (Answer> 0) System.out.println (Answer); Else System.out.println ( "- 1");} Public stable long facts (long n) {long ans; if (n == 1 || n == 0) return 1; other ans = fact ( N -1) * (n); answer to return;} Public stable long combination (long n) {if (n == 0) 0; if (n == 1) 0; if (n == 2) returns 1 ; And return ((fact (n)) / ((fact (n -2)) * 2));}  

}

Why this problem is coming Is the reason for any possible runtime error cause?

"strange" run time error is that After the next, with a typed return after

  $ java TestClass 42  

nextInt ()), a line of stdin.nextLine () Reads.

Administration (0, 0);

leads to the call

  Facts (n-1)  

with n == 0, And since then the stack overflow in a very long end recursion ...

I think you can fix it easily.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -