Results 1 to 2 of 2
- 12-14-2012, 09:43 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 28
- Rep Power
- 0
Need help with GUI and integers(just some basic things)
Hi so im sorta new to Java, and in one of my programs, i am doing the Hailstone numbers algorithm, and if you don't know, they work like this: if a number is odd, multiply it by 3 and add one, and if it is even, divide by two, and keep doing this til u get 1. So my question is, i am using an if statement, which will work when i get the value of x(my int) from the label. my statement is: if(x==even) but it doesn't work because even is not a method. so what can i do to make it so that if x is even, then do blah blah blah (i know how to code the rest).
- 12-14-2012, 09:50 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: Need help with GUI and integers(just some basic things)
Check out the % (remainder) operator. 42%10 is 2, 666%37 is 0, etc. Because 666%37==0 is true we can conclude that 37 is a factor of 666.
Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
Similar Threads
-
Understanding Hibernate, things it can does or not
By Fred2040 in forum HibernateReplies: 1Last Post: 07-27-2012, 09:24 AM -
Help with printing simple things.
By Aimforthehead in forum New To JavaReplies: 4Last Post: 12-02-2011, 01:01 AM -
Need Help. with two simple things
By Fred1 in forum New To JavaReplies: 32Last Post: 04-28-2011, 02:35 AM -
things necessary to take note of before going to learn EE
By kulangotski in forum New To JavaReplies: 0Last Post: 12-28-2010, 06:30 AM -
XML, and other things.
By Tortex in forum New To JavaReplies: 5Last Post: 03-28-2010, 05:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks