import java.util.*;
class Sum
{
public static void main(String args[])
{
int n,sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
n=sc.nextInt();
sum=series(n);
System.out.println("Sum="+sum);
}
static int series (int n)
{
if(n==1)
return 1;
else
return (n+series(n-1));
}
}
class Sum
{
public static void main(String args[])
{
int n,sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
n=sc.nextInt();
sum=series(n);
System.out.println("Sum="+sum);
}
static int series (int n)
{
if(n==1)
return 1;
else
return (n+series(n-1));
}
}
No comments :
Post a Comment