| Welcome to the Heavenly Host Elementary School: A Corpse Party Forum. We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
- Pages:
- 1
- 2
| Java Help | |
|---|---|
| Topic Started: December 12, 2015, 2:58 am (440 Views) | |
| logonin | December 12, 2015, 2:58 am Post #1 |
![]()
Corpse Party Fanboy
|
I know this not a programming forum but there seems to be some very smart programmers here on the forums so I guess its worth a shot to ask this. In java I need to make a variation of the famous "FizzBuzz" program where I have to count up to any number the user inputs and then only print 11 numbers per line. My code can do all of that but for some reason it repeats the same number 11 times each line. Can someone please help me fix it? Here is my code
and this is the output I get if I input "50" "CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza CozaLozaWozaCozaLoza 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 4 4 4 4 4 4 4 4 4 4 4 Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza 8 8 8 8 8 8 8 8 8 8 8 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza 11 11 11 11 11 11 11 11 11 11 11 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 13 13 13 13 13 13 13 13 13 13 13 Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 19 19 19 19 19 19 19 19 19 19 19 Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 22 22 22 22 22 22 22 22 22 22 22 23 23 23 23 23 23 23 23 23 23 23 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza 26 26 26 26 26 26 26 26 26 26 26 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza 29 29 29 29 29 29 29 29 29 29 29 CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza 31 31 31 31 31 31 31 31 31 31 31 32 32 32 32 32 32 32 32 32 32 32 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 34 34 34 34 34 34 34 34 34 34 34 Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 37 37 37 37 37 37 37 37 37 37 37 38 38 38 38 38 38 38 38 38 38 38 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza 41 41 41 41 41 41 41 41 41 41 41 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza 43 43 43 43 43 43 43 43 43 43 43 44 44 44 44 44 44 44 44 44 44 44 CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza 46 46 46 46 46 46 46 46 46 46 46 47 47 47 47 47 47 47 47 47 47 47 Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza Woza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza" Any help would be appreciated. Thanks ![]() |
![]() |
|
| Rohzek | December 12, 2015, 3:24 am Post #2 |
|
Leader
|
I'm not exactly familiar with this particular idea so I don't know what I'm looking for exactly but... If the output itself looks fine, EXCEPT that it's repeated 11 times... What is the second for loop supposed to do? It's looping through 11 times... could be your culprit? |
![]() | |
![]() |
|
| Luph | December 13, 2015, 12:29 am Post #3 |
|
╰ᕦ╯( O++O )╰ᕤ╯
|
It's the inner loop. What you're doing is printing each number from 0 to number that user input 11 times. If you want to have 11 numbers on each line, then what you can do is to have a counter variable that keeps track how many numbers you have printed in a single line and if you have printed 11 numbers, you print a newline character and reset the counter. Edited by Luph, December 13, 2015, 12:37 am.
|
|
Ain't no party like Corpse Party Satoshi x Yoshiki is canon
| |
![]() |
|
| logonin | January 7, 2016, 1:28 am Post #4 |
![]()
Corpse Party Fanboy
|
Hi I am a beginner to Java and I really need some help. I know this is not a programming forum but I have gotten some good advice from here in the past. I have to add to some code that has been provided to do the following "Write a method isEventhat determines whether an integer is even or odd. The method should take an integer argument and return true if the integer is even. If the integer is odd, it should return false." Here is the code I was provided
And here is my attempt at doing what the project asks
I am getting the following errors from this code " [line: 5] Error: cannot find symbol symbol: class MethodPractice location: class NewTest3 [line: 5] Error: cannot find symbol symbol: class MethodPractice location: class NewTest3 [line: 22] Error: cannot find symbol symbol: variable mp location: class NewTest3" So how can I fix these errors? I am confused with the code my teacher has provided. I am also pretty sure we are not aloud to change it and I am positive we are not aloud to simply delete it. So yeah any advice will be greatly appreciated. Thanks ![]() Edited by logonin, January 7, 2016, 1:30 am.
|
![]() |
|
| Skybird | January 7, 2016, 2:05 am Post #5 |
![]()
Grindblues
![]()
|
I've combined these two topics as they are of similar subject. |
| [ - Gran is the real deal. - ] | |
![]() |
|
| Rohzek | January 7, 2016, 2:13 am Post #6 |
|
Leader
|
Line 5 instantiates a class named "MethodPractice" under the variable name mp... It seems you don't have a class called MethodPractice and you're trying to instantiate one. Since that was all the code you were provided, I assume you were supposed to create it? I was also going to say "Isn't this the same topic as the last one?" haha. |
![]() | |
![]() |
|
| logonin | January 7, 2016, 2:43 am Post #7 |
![]()
Corpse Party Fanboy
|
Actually I do... I just found this file along with the other one my teacher provided us
So do I just have to copy and paste everything I did in there under the problem 1 section in the code? Edited by logonin, January 7, 2016, 2:45 am.
|
![]() |
|
| Rohzek | January 7, 2016, 3:17 am Post #8 |
|
Leader
|
Not to sound rude friend... but without proper context (and due to lack of sleep) I'm not entirely sure what's going on in your version of the class (NewTest2aq).. I don't mean anything by it, Sorry. ●︿● Don't know how much help you want and I feel bad for helping you with I assume homework so I'll be as brief as possible but... Line 13 of the original (Lesson18Test) class is calling for a method in MethodPractice called isEven which should return a boolean.
So under Problem#1 you'll be needing to create that.
And then inside of that you'll need to check the number to see if it's even or odd. Two quick ways I know of doing that is modulus division by 2 (if the answer is 0 it's even) or checking the bit to see if it's even or odd. Both can be done in one line of code so neither is easier or harder (but modulus division can be a little slower if you have to do a lot of it.. won't make a difference here) |
![]() | |
![]() |
|
| logonin | January 7, 2016, 3:30 am Post #9 |
![]()
Corpse Party Fanboy
|
Thank you so much! You are a life saver! |
![]() |
|
| Rohzek | January 7, 2016, 3:49 am Post #10 |
|
Leader
|
It's nothing, always happy to help! o(^▽^)o |
![]() | |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Science Lab · Next Topic » |
- Pages:
- 1
- 2














12:03 PM Jul 13