• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iterations - finding the same value for 2 variables

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone.....

I'm trying to make a program which can calculate the turning effects of rod.....

i have made this :


but i want to calculate the value which the program will get same for both moment and moment2


i tried this but i didn't work.... :



this tells me that i need a boolean rather than an int but it doesn't even allow casting...

so what should i do to get that value which is same for both the variables???

please help......its my physics homework.......
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
= is an assignment operator
== is a comparison operator
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words: = != ==.
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,

i tried that but then also it didn't work......

see my current code is :




I dont get any value in the command line.......

What should i do???

please help.......
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fix your code's logic--it's almost certainly not doing what you think it is. Printing out the iteration count and the two variables you're modifying might be a good place to start.
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's iterate a bit manually, shall we?

force == 2, distance == 18 => moment == 36
force2 == 2, distance2 == 9 => moment2 == 18

force == 3, distance == 18 => moment == 54
force2 == 3, distance == 9 => moment == 27

force == 4, distance == 18 => moment == 72
force2 == 4, distance == 9 => moment == 36


As you see, the way your code works now moment will always be twice as large as moment2.

So you want to find a moment and moment2 that are equal? Then you should increment either force or force2:
I know find that moment == 36 will break the loop.

If you don't want that break in there you can increase both force and force2 instead. You then get all multiples of 18 except for 0 and 18 itself (since moment will always be larger than 18).
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... Seems like giving a hint would have been enough.
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks,
joanne neal, david newton and rob prime for answering.......


hey rob thanks......

i finally solved the problem using your suggestion.......

i just removed the break; method.....and in place of that i put force++

and i added a limit to the while condition and then i got like 100,000 values where those objects can be balanced......

thnx a lot everyone.....
 
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic