Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prining a line of *****

Status
Not open for further replies.

eadams

Programmer
Oct 11, 2007
1
0
0
US
i am trying to print out a line of * such as:
*****
*******
and so on. i have tried to use the system.out.print("*"); with a for loop. it doesn't work the way i want it to. any help will be greatly appreciated
 
Use printf "system.out.printf();"

Code:
import java.awt.*;
import java.applet.*;

public class StringTest {

	public static void main (String[]  args){
	String MyAst = "*****************";

	System.out.printf("%1.3s\n", MyAst);
	System.out.printf("%1.5s\n", MyAst);
	System.out.printf("%1.8s\n", MyAst);
	System.out.printf("%1.5s\n", MyAst);

	}
}




Thanks,
Nate_Bro
 
printf? That's C, not Java. That should be println.

Javadoc for System.out

And you should ask this kind of questions in the Java forum, this one is intended only for J2EE questions.

Cheers,
Dian
 
I did, I even tried to compile your code and it doesn't compile on my JDK.

Maybe you can provide us a link to the documentation or tell us which Java version are you using.

Cheers,
Dian
 
Humm, you're rigth. That's since 1.5, a new convenience method.

Anyway, and back to the topic, the nice way to do that in Java is

Code:
System.out.println("************");


Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top