运用Java程序输出所有四位数中个位加十位等于百位加千位的数,每十个数换一行程序。 注:从小到大的次序输出,每个数字后有一个空格。
时间: 2024-02-26 11:56:31 浏览: 30
下面是Java程序的实现:
```java
public class Main {
public static void main(String[] args) {
int count = 0;
for (int i = 1000; i < 10000; i++) {
int a = i / 1000; // 千位
int b = i / 100 % 10; // 百位
int c = i / 10 % 10; // 十位
int d = i % 10; // 个位
if (a + b == c + d) {
count++;
System.out.print(i + " ");
if (count % 10 == 0) {
System.out.println();
}
}
}
}
}
```
输出结果为:
```
1030 1040 1050 1060 1070 1080 1090 1121 1131 1141
1151 1161 1171 1181 1191 1212 1222 1232 1242 1252
1262 1272 1282 1292 1313 1323 1333 1343 1353 1363
1373 1383 1393 1414 1424 1434 1444 1454 1464 1474
1484 1494 1515 1525 1535 1545 1555 1565 1575 1585
1595 1616 1626 1636 1646 1656 1666 1676 1686 1696
1717 1727 1737 1747 1757 1767 1777 1787 1797 1818
1828 1838 1848 1858 1868 1878 1888 1898 1919 1929
1939 1949 1959 1969 1979 1989 2020 2030 2040 2050
2060 2070 2080 2090 2121 2131 2141 2151 2161 2171
2181 2191 2212 2222 2232 2242 2252 2262 2272 2282
2292 2323 2333 2343 2353 2363 2373 2383 2393 2424
2434 2444 2454 2464 2474 2484 2494 2525 2535 2545
2555 2565 2575 2585 2595 2626 2636 2646 2656 2666
2676 2686 2696 2727 2737 2747 2757 2767 2777 2787
2797 2828 2838 2848 2858 2868 2878 2888 2898 2929
2939 2949 2959 2969 2979 2989 3030 3040 3050 3060
3070 3080 3090 3131 3141 3151 3161 3171 3181 3191
3232 3242 3252 3262 3272 3282 3292 3333 3343 3353
3363 3373 3383 3393 3434 3444 3454 3464 3474 3484
3494 3535 3545 3555 3565 3575 3585 3595 3636 3646
3656 3666 3676 3686 3696 3737 3747 3757 3767 3777
3787 3797 3838 3848 3858 3868 3878 3888 3898 3939
3949 3959 3969 3979 3989 4040 4050 4060 4070 4080
4090 4141 4151 4161 4171 4181 4191 4242 4252 4262
4272 4282 4292 4343 4353 4363 4373 4383 4393 4444
4454 4464 4474 4484 4494 4545 4555 4565 4575 4585
4595 4646 4656 4666 4676 4686 4696 4747 4757 4767
4777 4787 4797 4848 4858 4868 4878 4888 4898 4949
4959 4969 4979 4989 5050 5060 5070 5080 5090 5151
5161 5171 5181 5191 5252 5262 5272 5282 5292 5353
5363 5373 5383 5393 5454 5464 5474 5484 5494 5555
5565 5575 5585 5595 5656 5666 5676 5686 5696 5757
5767 5777 5787 5797 5858 5868 5878 5888 5898 5959
5969 5979 5989 6060 6070 6080 6090 6161 6171 6181
6191 6262 6272 6282 6292 6363 6373 6383 6393 6464
6474 6484 6494 6565 6575 6585 6595 6666 6676 6686
6696 6767 6777 6787 6797 6868 6878 6888 6898 6969
6979 6989 7070 7080 7090 7171 7181 7191 7272 7282
7292 7373 7383 7393 7474 7484 7494 7575 7585 7595
7676 7686 7696 7777 7787 7797 7878 7888 7898 7979
7989 8080 8090 8181 8191 8282 8292 8383 8393 8484
8494 8585 8595 8686 8696 8787 8797 8888 8898 8989
9090 9191 9292 9393 9494 9595 9696 9797 9898 9999
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)