java 文本输出_格式化文本输出Java SE

我正在尝试从Java中的System.out.println打印一些ASCII艺术作品.当我这样做时,尽管源代码中所有的空格都消失了.打印出来的是一堆毫无意义的废话.图1显示了源代码的外观以及ASCII图片的外观.图2显示了程序运行时横幅的实际外观.

我的问题是如何按预期方式打印ASCII艺术作品?如何以使横幅易于阅读的格式打印ASCII艺术作品?

例如,使用Python,我可以通过使用三引号轻松地完成这项工作. Java是否具有类似的文本机制?

0765af5baabae398ca9cb0c6270a8a6f.png

图1:ASCII外观应该是什么样

a5c6e71cf0e07de6fa2ba8266b671015.png

图2:程序运行时的ASCII外观

请查看我的源代码,如下所示:

package Boring;

import java.util.Scanner;

public class EnchantedBoringLevel {

public EnchantedBoringLevel () {

System.out.println("\n\n\n\n\n\n\n\n\n\n\n");

/* System.out.println("\n" +

"EEEE h t d BBBB FFFF t " +

"E h t d B B ii F t " +

"EEE nnn ccc hhh aa nnn ttt eee ddd BBBB ooo rrr nnn ggg FFF ooo rrr eee ss ttt " +

"E n n c h h a a n n t e e d d B B o o r ii n n g g F o o r e e s t " +

"EEEE n n ccc h h aaa n n tt ee ddd BBBB ooo r ii n n ggg F ooo r ee ss tt " +

" g " +

" ggg "

);

*/

System.out.println("***Enchanted Boring Forest***");

System.out.println("Welcome to another boring level of this video game!\n\n\n\n");

this.enchant();

}

public void enchant() {

System.out.println("You find yourself in a magical forest all alone.\nYou hear music in the distance.\n" +

"An elf appears and takes you to their tree house mansion.");

System.out.print("The elf prince offers you three choices 1) invisible ring, 2) galactic sunglasses, 3) a map of the enchanted forest. Which do you choose?");

Scanner enchanted_choice = new Scanner(System.in);

String choice;

choice = enchanted_choice.next();

switch(new Integer(choice)) {

case 1:

System.out.println("You chose the invisible ring");

new BoringInvisibleRing();

break;

case 2:

System.out.println("You chose the galactic sunglasses");

new BoringGalacticSunglasses();

break;

case 3:

System.out.println("You chose the map of the enchanted forest");

break;

default:

System.out.println("You shot yourself in the face.");

}

}

}

解决方法:

控制台会包装您的文本.在控制台设置中设置高列号

标签:java

来源: https://codeday.me/bug/20191011/1893836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值