A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
class ev
{
int c=0;
long lcm(long d,int dd)
{
long div=d;
for(int i=1;i<=dd;i++) // finds the smallest divisible number between 1 to 10
{
if(div%i==0)
{
c=c+1; //counts the number of times the d variable gets divisible and sum them
}
}
if(c==dd) // if sum comes out to be 10 then we know the d variable is completely divisible by every number from 1 to 10
{
return div;// return the number
}
else
{
++div; // increment the number
c=0; // reset
anonymous
 5 years ago
class ev { int c=0; long lcm(long d,int dd) { long div=d; for(int i=1;i<=dd;i++) // finds the smallest divisible number between 1 to 10 { if(div%i==0) { c=c+1; //counts the number of times the d variable gets divisible and sum them } } if(c==dd) // if sum comes out to be 10 then we know the d variable is completely divisible by every number from 1 to 10 { return div;// return the number } else { ++div; // increment the number c=0; // reset

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hi! What's your point?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sir i have attached a java file and i want to calculate the least number divisile by 1 to 20 each , I am able to calculate for 1 to10 but when i do it for 1 to 20 it gave me stackoverflow error

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Perhaps it's related to the allowed memory for java. Try with the Xms and Xmx from the java command. If it doesn't change, then it's related to your program itself. I will have a look at your file as soon as I get my coffee break :)

shadowfiend
 5 years ago
Best ResponseYou've already chosen the best response.1You've decided to implement this algorithm recursively. That's fine, but if it takes more recursive calls to reach a number divisible by all numbers from 1 to 10 than there is allowed stack space on the JVM, you'll get a StackOverflow error. If your prints show that you pass a number divisible by all numbers from 110 and don't stop, then you logic for checking that is wrong. If, however, that doesn't happen, then you'll have to implement the algorithm iteratively (= with a loop) instead of recursively in order to reach the answer.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Find the primes that go into each of the numbers 120 and then look for overlap. Remove the overlap and multiply the remaining numbers out to get the final number.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.