The following code works fine But as soon i take any integer input at the beginning it goes in infinite loop. I need the integer value for testcases.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner stdin = new Scanner(System.in);
//HERE I JUST INPUT AN
// INT VALUE PROGRAM GOES INFINITE LIKE int t = stdin.nextInt();
long count = 0;
String str = stdin.nextLine();
char[] c = str.toCharArray();
for(int j=0;j<str.length();j++){
switch(c[j]){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
count++;
default : break;
}
}
arrangement(count,str.length());
}
public static void arrangement(long v,long n){
long total = fact(n);
long together = ((combination(v))*(fact(n-1))*2);
long answer = (total - together);
if(answer>0)
System.out.println(answer);
else
System.out.println("-1");
}
public static long fact(long n){
long ans;
if(n==1 || n==0)
return 1;
else
ans = fact(n-1)*(n);
return ans;
}
public static long combination(long n){
if(n==0)
return 0;
if(n==1)
return 0;
if(n==2)
return 1;
else
return ((fact(n))/((fact(n-2))*2));
}
}
why is this problem occuring? any possible runtime error reason>?