在多行控制台上打印java [英] java printing on console with multiple lines

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

问题描述

我正在编写一个程序,我想在控制台上输出一个输出



I am writing a program and i wanted an output as a follow on the console

ID               DESCRIPTION                  QUANTITY
--------------------------------------------------------
1                This is the first             10
                 product of our store
2                This is the second 
                 product of the program        20

and so on





我可以格式化除了描述部分之外的其他部分。总的来说我想要的是我希望用户输入10个带有详细描述的条目,并在控制台上以与上面所示相同的格式显示输出。无论描述有多长,我如何在不危及显示器的其他部分的情况下完成多行描述。

谢谢



I could format the other part of the thing except the description part. Overall what i want is that I want user to enter lets say 10 entry with a long description for each and display the output on the console in the same format as i have shown above. How do I accomplish the multiple lines description without jeopardizing the other part of the display no matter how long the description is.
Thanks

推荐答案

查看描述的长度。

如果超出可用空间,回顾最后适合的空间并打印到那里。

打印数量。

从字符串中删除刚刚打印的东西。

空格填写说明栏,并重复 - 这次不打印数量。
Look at the length of the description.
If it exceeds the available a space, look back for the last space that does fit and print up to there.
Print the quantity.
Remove the stuff you just printed from the string.
Space fill up to the description column, and repeat - not printing quantities this time.


这篇关于在多行控制台上打印java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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