Results 1 to 8 of 8
Thread: Solve my program
- 12-16-2008, 01:03 PM #1
Member
- Join Date
- Dec 2008
- Location
- Davao Oriental
- Posts
- 29
- Rep Power
- 0
- 12-16-2008, 03:05 PM #2
couple of things
- You have posted in the wrong part of the forum. This should probably be in the "New to Java" section. The mods can move it.
- You probably already know this, but the forum won't do your assignment for you. The forum will help you to learn how to do it. To get you started, here's a way to detect if a number is odd/even:
orJava Code:if (x % 2 == 0) // number is even
Do you know how/why the above code works ?Java Code:if (x % 2 != 0) // number is odd
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-19-2009, 05:51 AM #3
(i%2!=0) is the condition used to do this operation
- 01-19-2009, 07:04 AM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
it is quite strange for usually (i%1!=0) has been used. Try out the question(i%2!=0) is the condition used to do this operation
- 01-21-2009, 02:09 AM #5
If you divide x by 1 It will always equal It self so there will be no remainder
Example below
Writes on the command line 0 because there is no remainderJava Code:int x = 5; System.out.println(x % 1);
Writes on the command line .5 because .5 is the remainder of 5 / 2Java Code:int x = 5; System.out.println(x % 2);
The Modulus(%) function finds the remainder of a division .
but I would hope that you already knew that.
Hope that helps,
SariIf you don't try you can't succeed.
- 01-21-2009, 02:21 AM #6
ah... almost
Actually that's not entirely true... it prints 1, not .5. The reason being because:
- the remainder of 5/2 is not .5, it's 1
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-21-2009, 03:54 AM #7
I'm disappointed in myself messing up basic math oh well I think I got the point across
If you don't try you can't succeed.
- 01-21-2009, 06:20 AM #8
mod % means reminder
simple solution...
multiplication is related with addition,
division is related with subtraction,
modulo is the remainder...
for example,
2*5 is 10
how, 2+2+2+2+2 is 10...
similarly division
5/2 is 2 because you can subtract 2 only 2 times from 5
(1st time)5-2=3 (3 remainder)
(2nd time)3-2=1 (1 remainder)
so, 5/2 is 2 and the remainder is modulo(%)...here its 1.
understand the logic its very important...
Similar Threads
-
Help me to solve problem
By mansoorhacker in forum Forum GuidesReplies: 8Last Post: 01-24-2009, 06:29 PM -
Solve my Problem
By kyo in forum New To JavaReplies: 1Last Post: 12-16-2008, 02:22 PM -
Help me to solve problem
By mansoorhacker in forum New To JavaReplies: 3Last Post: 11-13-2008, 08:15 AM -
how to solve capital country program in java applet
By shadab in forum AWT / SwingReplies: 2Last Post: 08-27-2008, 02:40 PM -
Help mi solve my error
By Deon in forum New To JavaReplies: 3Last Post: 01-11-2008, 05:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks