![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2008
Posts: 3
Rep Power: 0
![]() |
count multiples of 6 between two numbers given by the user.
Hi all, Is my answer true .. and I want your opinion in my answer
• Write a program fragment to count multiples of 6 between two numbers given by the user. java Syntax (Toggle Plain Text)
Thank you.. Last edited by big_k105; May 2nd, 2008 at 11:05 AM. Reason: Added Code Tags |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: count multiples of 6 between two numbers given by the user.
I think you got it. Quick note though, the two number (X and Y) should be inputted by the user, not you, so you should probably ask for them.
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Re: count multiples of 6 between two numbers given by the user.
Your logic is not quite correct. Try X=35, Y=35 or X=42, Y=48.
Hint: Use a while loop instead of a do/while loop. The latter should be avoided when possible. (There is another problem with your code, but I will let you figure out what it is.) |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Re: count multiples of 6 between two numbers given by the user.
i pointed this out to him in his other post, as it was a very similar problem and he made the very same logically mistake as he has done here.
__________________
Steven Skiena - Algorithms ,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],brainf**k -- It's such a pretty language |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Oct 2006
Posts: 311
Rep Power: 3
![]() |
Re: count multiples of 6 between two numbers given by the user.
I have a tip; don't make it so obvious that you are doing homework problems. Goodness.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2008
Posts: 11
Rep Power: 0
![]() |
Re: count multiples of 6 between two numbers given by the user.
I agree with titaniumdecoy...don't use a do...while loop. Use a while loop (or I suppose a for loop would work in this case as well). Also, have X and Y be input. You could use a scanner or you could use a JOptionPane. Also, why do you increment X before you check to see if it's a multiple of six?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| code to add numbers in an array | truBlu1 | Java | 9 | Oct 12th, 2007 11:08 PM |
| Post count adjustments | big_k105 | Community Announcements and Feedback | 26 | Nov 28th, 2005 6:02 PM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 4:41 PM |
| Loading and Destroying web user controls into a panel | see07 | C# | 0 | Feb 2nd, 2005 1:38 PM |
| Show web user control hidden | see07 | C# | 1 | Feb 2nd, 2005 11:35 AM |