I am having a problem while writing this java for loop code. I am trying to print "NETProduct" a number of times which is depending on the passed "length" variable and to print after the word "NETProduct" the current value of the length + " ," and when it reached the last "NetProduct", it shoudn't produce "," after the "NETProduct" variable.
As an example:
So, what I am looking for is for the result:
and the result is in the same line.
Can you please help
fred rosenberger wrote:The problem is this:
sentence = "NETProduct" + i + ",";
you have explicitly told it to print a comma after every "NETProductx". simply put in some logic to decide if you want a comma or not. something like this (which has not been tested in any way)
Or he could simply include the comma before the inclusion of "i" in the string, such as
Hope it helped :P