• Post Reply Bookmark Topic Watch Topic
  • New Topic

A System.out.print question  RSS feed

 
frank mango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a method wherein I use a for loop to print to the output terminal the elements of an array[].
I would like to have these elements print to a single line as opposed to new line for each array element..........
How can I make this happen? many thanks
a very newbe
Mango
 
MuraliKrishna Rayapudi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use System.out.print, instead System.out.println
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch both of you
 
frank mango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for your help. I however still have a problem. It goes like this.
I have a HashMap with student names as keys and the values are arrays of test results.
The code I have written to print the information is below.
public void showQuizMarks()
{
String key = null;

int []returnThis = new int[QUIZZES];

Iterator iterator = quizMarks.keySet().iterator();
while( iterator. hasNext() )
{
key = iterator.next().toString();
returnThis = quizMarks.get(key);
System.out.println("Quiz marks for: " + key );

for(int i = 0; i < QUIZZES ; i ++)
{

System.out.print( returnThis[i]+ " " );

}
}
This code produces a result that looks like this:

Quiz marks for: ppp
0 0 0 0 0 0 0 0 0 0 Quiz marks for: HHH
0 0 0 0 0 0 0 0 0 0 Quiz marks for: KKK
0 0 0 0 0 0 0 0 0 0

I would like it to look like this:

Quiz marks for: ppp
2 0 4 7 0 0 0 0 8 0
Quiz marks for: HHH
4 9 2 0 0 0 0 0 0 0 0
Quiz marks for: KKK
3 9 7 6 2 0 0 0 5 0 09

I have been fooling around for hours trying to produce this result but thus far haven't the wit to put it together.
floundering
mango
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,

There are few ways, one would be to add a empty SOP after the for loop. . System.out.println("");

 
frank mango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have taken a few seconds off from kicking myself to say "THANKS!! Balu Sadhasivam
Mango
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:System.out.println(""); [/code]
You mean "System.out.println();" surely?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is worthwhile learning about formatting printing with printf; you should use the %n tag to enter "new line".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!