Tenth ICSE Computers
Please solve :)
Write a Program to pass 2 int values to a function such that the first number is lower than the second number.
The int values will be in the range and the function would return the sum of the numbers in that range
Answers
Answered by
1
import java.util.*;
class ICSE
{
public int range(int a,int b) // to accept the value
{
int i,sum=0;
for(i=a;i<=b;i++) // to produce a range
{
sum=sum+i; // to store the sum
}
return(sum); // to Return sum to p
}
public static void main()
{
Scanner sc=new Scanner(System.in);
ICSE ob =new ICSE();
int m,n,p;
System.out.println("Enter your first number ");
m=sc.nextInt();
System.out.println("Enter your second number greater than first ");
n=sc.nextInt();
int p=ob.range(m,n); // to pass the value
System.out.println("Range is "+p);
}
}
Hope it will help you @
amannishad0512p5zxh6:
Go through the answr
Similar questions