• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formal parameter; example of Euclid's algorithm  RSS feed

 
Miljan Puletic
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

By knowing that int m and int k are placeholders (formal parameters) for entered values of x and y, how come, if for example x < y, the program still calculates the correct result ? I wrote int s = m % k so that should mean that s = x % y ? How program knows which number is greater and which one is smaller ? Bottom line, if I enter 24 and 6, I get 6 as result (which is OK), but when I enter 6 and 24 I get same result, which is also OK, just I dont understand how ??

 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add some print statements.
 
Miljan Puletic
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey,

Since I am complete newbie, would you be willing to explaint a little bit more what these print statements do, I dont quite understand how those print statements determent which number is greater and which is smaller.
 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miljan Puletic wrote:Hi Carey,

Since I am complete newbie, would you be willing to explaint a little bit more what these print statements do, I dont quite understand how those print statements determent which number is greater and which is smaller.


You might want to get an IDE like Eclipse, copy the code into it, and debug it - step through it line by line. If you don't know how to do that, there are tons of tutorials on that. Being able to step through your code in a debugger is critical to understanding and fixing code problems (logging being another).

Google (or Duck) the Java "printf" and read the documentation.

Try to write your own "printf" statement so you can see what it does.

That's how we all learn this stuff.

-- mike
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:. . . Google (or Duck) the Java "printf" and read the documentation. . . .
but I can save you the searching; try in the Java™ Tutorials or (2nd Tutorials section) and you will find the full details in the Formatter class documentation, though the latter will take ages to read.

Why are you using one‑letter variable names? Did you copy them from somewhere (if so, please tell us where)? If you come back in six months you will not have the faintest idea what s m and k mean.
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miljan Puletic wrote:Hi Carey,

Since I am complete newbie, would you be willing to explaint a little bit more what these print statements do, I dont quite understand how those print statements determent which number is greater and which is smaller.
In long hand would be:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!