|
|
|
|
New Member
|
|
Nov 16, 2015, 07:59 AM
|
|
My loop only calculates odd numbers, not even, please help.
while ( x < 20 ) {
if ( r == 11 ) {
r = 0;
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
x++;
}
if ( s == 11 ) {
s = 0;
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
x++;
}
texts = texts + columnNames[r] + " : " + firstevolutiondata[x][s] + " \n";
s++; r++;
textArea.setText(texts);
System.out.println(x);
}
|
|
|
Adult Sexuality Expert
|
|
Nov 16, 2015, 09:19 AM
|
|
Could it be that you're incrementing X twice before you get to the bottom?
while (x < 20)
if(r == 11)
{
do stuff
x++;
}
if(s==11)
{
do stuff
x++;
}
do stuff;
s++;r++;
do more stuff
}
It seems that you're populating a 11x20 array. The way you're doing it, you're skipping over an column. I would reduce s,r to one value, call it n. When n is eleven you do the stuff, reset n to zero, do the stuff, then increment x. That should solve the problem.
|
|
|
New Member
|
|
Nov 17, 2015, 08:06 AM
|
|
Thanks for your help, I did what you said, but, it says that this line is the error :texts = texts + columnNames[n] + " : " + firstevolutiondata[x][n] + " \n";And I only get 0's, 1's, 2's and, 3's I'm utterly confused.
|
|
|
Adult Sexuality Expert
|
|
Nov 17, 2015, 08:33 AM
|
|
int n=0;
int x=0;
while ( x < 20 ) {
if ( n == 11 ) {
n = 0;
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
x++;
}
texts = texts + columnNames[n] + " : " + firstevolutiondata[x][n] + " \n";
n++;
textArea.setText(texts);
System.out.println(x);
}
That is the simple simplification. I don't know what the values of r and s were coming into the original code. What is this meant to do? What is the parameters of your assignment?
|
|
|
New Member
|
|
Nov 18, 2015, 07:48 AM
|
|
Originally Posted by CravenMorhead
That is the simple simplification. I don't know what the values of r and s were coming into the original code. What is this meant to do? What is the parameters of your assignment?
R & S were sort of the same thing, so, they're not really relevant anymore.
|
|
|
New Member
|
|
Nov 18, 2015, 08:03 AM
|
|
Originally Posted by CravenMorhead
That is the simple simplification. I don't know what the values of r and s were coming into the original code. What is this meant to do? What is the parameters of your assignment?
Here's the code as is now, I'm having troubles with it because it only prints the last result, which is " Froakie "
Program Example - Pastebin.com
|
|
|
Adult Sexuality Expert
|
|
Nov 18, 2015, 09:03 AM
|
|
That is for a simple reason.
texts = texts + "\n";
textArea.setText(texts);
texts = texts + "\n";
textArea.setText(texts);
Each time this is called it will overwrite the contents of the textArea. You don't see because it is happening too fast. If you put that "System.out.println(text)" at the bottom of the printstats function then you will see all the stats printed out.
Also this is a lesson in scope. You passing the string by value, the contents of it, to the print stat function. You get the contents of that string in your function but not the actual string value. All the changes you make to it will stay in the function. When you leave the function the copy of the string will be destroyed and WON'T be carried on. Each time you go into the printstats function you have an empty string. If you change the way you allocate the string before you pass it in, you should be able to collect all the stats.
string texts = new string("");
instead of
string texts = "";
you might get all the stats. It is hard to say.
Look at this for more information
Good luck.
|
|
|
New Member
|
|
Nov 19, 2015, 08:13 AM
|
|
Originally Posted by CravenMorhead
That is for a simple reason.
Each time this is called it will overwrite the contents of the textArea. You don't see because it is happening too fast. If you put that "System.out.println(text)" at the bottom of the printstats function then you will see all the stats printed out.
Also this is a lesson in scope. You passing the string by value, the contents of it, to the print stat function. You get the contents of that string in your function but not the actual string value. All the changes you make to it will stay in the function. When you leave the function the copy of the string will be destroyed and WON'T be carried on. Each time you go into the printstats function you have an empty string. If you change the way you allocate the string before you pass it in, you should be able to collect all the stats.
string texts = new string("");
instead of
string texts = "";
you might get all the stats. It is hard to say.
Look at this for more information
Good luck.
Thanks for all of your help, I finally figured it out, thanks to you! :D
|
|
Question Tools |
Search this Question |
|
|
Add your answer here.
Check out some similar questions!
Confused how my bank calculates the montly installment.
[ 2 Answers ]
I took a loan of 300,000. I am paying it over 3 years installments. The markup is 14%. The monthly fix payment would be 10,253. Can someone tell me how my bank calculated this monthly payment?
You can see how the page below calculates it?
http://www.realkerala.com/calc_emi.htm
GB
View more questions
Search
|