亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在第 11 行中,我該如何制作,這樣我就不需要使用這么多空格

在第 11 行中,我該如何制作,這樣我就不需要使用這么多空格

慕斯王 2024-01-05 14:59:54
如何在不更改格式的情況下刪除所有空格以及最好的選擇是什么,如果是的話我會使用 System.out.printf(); 或其他一些指令。請用java而不是C++回復。我真的很感激任何提供幫助的人,并且很樂意感謝他們幫助我解決自己的問題。public class WorldPopulation{    //main string    public static void main(String[] args) {             //prints title             System.out.println(" This is a estimate of world population growth within 300 year time span. ");            //prints number value            System.out.println("                       Numbers are in millions");            //number of rows and columns            final int ROWS = 6;            final int COLUMNS = 7;            //population numbers array            int [] [] populations =                {                        {106, 107, 111, 133, 221, 767, 1766},                        {502, 635, 809, 947, 1402, 3634, 5268},                        {2, 2, 2, 6, 13, 30, 46},                        {163, 203, 276, 408, 547, 729, 628},                        {2, 7, 26, 82, 172, 307, 392},                        {16, 24, 3, 74, 167, 511, 809}                };            //continents array            String[] continents =                {                        "Africa",                        "Asia",                        "Australia",                        "Europe",                        "North America",                        "South America"                };            //prints the years used in the estimation                   System.out.println("                Year 1750 1800 1850 1900 1950 2000 2050");            //print population data            for (int i = 0; i < ROWS; i++)    {                       //print i'th row                   System.out.printf("%20s", continents[i]);            //prints the columns and the rows            for (int j = 0; j < COLUMNS; j++) {                System.out.printf("%5d", populations [i] [j]);            }                System.out.println(); //start new line at end of row        }
查看完整描述

1 回答

?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

你可以這樣做:

System.out.format("%15s%s", "", "Test");

這里有一個長度為 15 的字符串,后面跟著一個未定義的字符串。由于第一個格式化的字符串是空字符串,因此將打印 15 個空格。


查看完整回答
反對 回復 2024-01-05
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號