0

Hi, I'm wondering how I can accomplish this.

Suppose I have the following array

String[] randomText = {"hi", "hello", "hey there"}

;

If I want to print the array I only know how to do so line by line.

for (int num = 0; num < randomText.length; num++){
	System.out.println(randomText[num]);
}

Can someone point me in the right direction?

3
Contributors
3
Replies
9
Views
9 Years
Discussion Span
Last Post by MrDiaz
0

Yeah, what exactly do you mean? System.out.println() will print out each element on a new line.. if you use System.out.print(), then you can print each element on the same line..

for (int i = 0; i < randomText.length - 1; i++)
	System.out.print(randomText[i] + " ");
System.out.print(randomText[randomText.length - 1]);
//Prints out randomText[] on one line, delimited by spaces.
0

It was the System.out.print statement I guess, I missed that hehe.

Thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.