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?

Recommended Answers

All 3 Replies

System.out.print("I will print on same line");

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.

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

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.