The toString() method was for debugging. It would be taken out when the debugging was done.
Are you done with this project now? Not interested in getting it to work now that its been turned in?
Type: Posts; User: Norm
The toString() method was for debugging. It would be taken out when the debugging was done.
Are you done with this project now? Not interested in getting it to work now that its been turned in?
Here are a couple of suggestions to start with:
0) fix the formatting so the code is readable
1)Change the variable names from n and m to numKids and numWords to make the code readable
2)Debug it...
No. It looks like a bunch of random code without any meaning.
Post#4 was much closer, but I can not believe you wrote it.
You posted the stack trace in posts#17, 19, 21 and 25
It starts with:
Exception in thread ...
and is followed by several lines that begin with
at ...
at ...
Where is the stack trace?
That has happened several times in this thread. You should know by now how to fix it.
BTW Most of your comments only say what the code is obviously doing. They should...
Does it compile? If it does then the code is legal.
There are no comments with the code describing what its logic is supposed to be so it's hard to see if the code is doing what the programmer...
Use one int value in a slot to show the child is present and have another value to show that the child has been removed. For example: 0 means child is present and 1 means the child has been removed....
Is the code in an infinite loop? To see, add some println() statements inside of the loops. Have them print out the values of the variables that are controlling the looping. The values printed will...
Did you read posts #18 and 24 about how to code the termination condition in a for loop?
BTW The code should use the array's .length field to test the end of the array, not the variable:n
Yes it does. The line number is given in the stack trace:
The error is on line 20.
Paste all the lines that define and set values for the code used on line 20.
Please copy the statement where the error happens and paste it here.
From post#18 (you should read what has been posted)
What statement is giving the error? If its in a for loop:
Change the code so the index stops before it goes past the end of the array.
If the array has 10 slots, the indexes range from 0 to 9 (the...
Look at how to code a for statement. The compiler doesn't like what is coded now.
See the tutorial: The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
A for...
The correct technique works with all arrays. What is in the array is not relevant.
The for loop's termination condition should be when the value of the index matches the array length.
Keep...
The code in post #4 shows a technique for using an array in a circular way. If you wrote that, you know how to do it.
The code is comparing an int: j with a boolean: kids[n-j]
That is not...
The code at line 17 used an index (10) past the end of the array. Look at the code on line 17 and before that line to see why it had an index value past the end of the array.
Remember: array...
Or have a boolean array named: removed with the default false (not removed) and true when removed.
That saves the useless loop to set the array's value to true. Use the default false values.
Please copy the full text of the error message and paste it here. It has important info about the error.
Where did the code in post#4 come from? Why is the code in post#8 so different?
import java.util.*;
public class Countout{
public static void main (String[]args){
Scanner in = new Scanner (System.in);
System.out.printf("Enter # of children [<=100]:");
int...