如何在不更改格式的情况下删除所有空格以及最好的选择是什么,如果是的话我会使用 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 个空格。
添加回答
举报
0/150
提交
取消