I want to loop through and print each value in the array. I want each int to be separated by commas but I don't want it to end with a comma.
for (int i=k-1; i<n; i=i+k)
System.out.printf("%d, ", array[i]);
System.out.printf("\n");
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I want to loop through and print each value in the array. I want each int to be separated by commas but I don't want it to end with a comma.
for (int i=k-1; i<n; i=i+k)
System.out.printf("%d, ", array[i]);
System.out.printf("\n");
First of all, make sure that the code after your for declaration is enclosed in brackets (otherwise only the first line of code after the for declaration will be executed every time the for loop iterates).
To help you more fully, I need to understand why you are using three integers -- i, k, and n -- to scroll through the values of one array... This seems rather messy; could you explain why you are using three integers?
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Just think a little and you will get what you want. These are not actually the programming problem but your thinking problem. Just do a little brain storming and you will conclude this.