有一个四位数字满足 千位数字+百位数字=十位数字 的特征求出此特征的数字
2 回答
已采纳
望远
TA贡献1017条经验 获得超1032个赞
public class HelloWorld {
public static void main(String[] args) {
for(int i=1000,count=0;i<10000;i++)
{
String string=new Integer(i).toString();
String []str=string.split("");
int []arr=new int[str.length];
for(int j=0;j<str.length;j++)
{
arr[j]=Integer.parseInt(str[j]);
}
if(arr[0]+arr[1]==arr[2])
{
System.out.print(string+" ");
count++;
if(count%10==0){
System.out.println();
}
}
}
}
}
添加回答
举报
0/150
提交
取消
