This is the program to show sum of series 1-(a^2/3!)+(a^4/5!)-(a^6/7!)+..... I used recursion show factorial of number
import java.io.*;
class Series{
public static void main(String args[])throws IOException{
int n,a;
double sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n & a");
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
a=Integer.parseInt(str);
for(int i=0;i<=n;i++){
sum=sum+(Math.pow(-1,i)*(Math.pow(a,2*i)/fact(2*i+1)));
}
System.out.println(sum);
}
static int fact(int n){
int fact=1,i;
for(i=1;i<=n;i++){
fact=fact*i;
}
return(fact);
}
}
output =
Exception in thread "main" java.lang.NumberFormatException: For input string: "3 6"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at Series.main(Series.java:12)
Please help me out it is showing error in java programming Exception in thread "main" java.lang.NumberFormatException