多次打印字符 [英] Print character multiple times

查看:63
本文介绍了多次打印字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一行中多次打印一个字符?

How can I print a character multiple times in a single line? This means I cannot use a loop.

我试图多次打印 _

我尝试了此方法,但是它不起作用:

I tried this method but it's not working:

System.out.println (" _" , s);

s 是变量。

推荐答案

您可以使用 System.out.print( _); ,因此您可以使用循环。 print 代替 println 不会附加换行符。

You can print in the same line with System.out.print(" _"); so you can use a loop. print instead of println does not append a new line character.

for (int i=0; i<5; i++){
    System.out.print(" _");
}

打印: _ _ _ _ _

这篇关于多次打印字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆