简体   繁体   English

找出前两位数字和后两位数字之和的平方等于数字本身的所有四位数字

[英]find all four digit numbers for which the square of the sum of the first two digits and the last two digits equal the number itself

The program that I wrote it is not working and I really don't know why.我编写的程序不起作用,我真的不知道为什么。 I would really appreciate your help.我将衷心感谢您的帮助。 Thank you谢谢

         for (int i = 1000; i <= 9999; i++){
             int n = i;
             int remandier1, remandier2,finalanswer;
             double result1=0;
             while(n != 0){
                 remandier1 = n % 100;
                 remandier2 = n /100;
                 finalanswer = remandier1 + remandier2;
                 result1 = Math.pow(finalanswer, 2);
             }
             if (result1 == n){
                 System.out.println(i);
             }
         }

So this program should execute all 4 digit numbers,the square of the sum of the first two digits and the last two digits should be equal to the number it self but mine it does nothing.所以这个程序应该执行所有 4 位数字,前两位数字和最后两位数字之和的平方应该等于它自己的数字,但我的它什么也不做。

You are using a loop based on n being different from 0, but n is never modified during the loop.您正在使用基于n不同于 0 的循环,但n在循环期间永远不会被修改。 How would the loop could actually stop.. looping?循环如何真正停止..循环? May be I'm missing something, but as I see it, n will forever be equal to the set value of i .可能是我遗漏了一些东西,但正如我所见, n将永远等于i的设定值。

while(n != 0)
{
    remandier1 = n % 100;
    remandier2 = n /100;
    finalanswer = remandier1 + remandier2;
    result1 = Math.pow(finalanswer, 2);
    // add something to stop the loop
    n = n - 1; // for example
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打印小于或等于56且数字总和大于10的两位数 JAVA - print two digit numbers which are less than or equal to 56 and the sum of digits is greater than 10 JAVA java:将代表两位数字年份的字符串转换为四位数 - java: Convert a string which represents a two digit year to four digits 计算小于或等于N的两个数字的对数,以使对数的数字总和为质数 - Count number of pairs of two numbers less than or equal to N such that Sum of the digits of numbers of pair is Prime 分析两位数字并打印其各个数字的总和 - Analyze a two digit number and print sum of its individual digits 检查这两个数字是否等于n位有效数字 - Check if the two numbers are equal to n significant digits 递归方法,打印的数字大于或等于第一个数字且低于最后一个数字 - Recursive method that prints all of the digits in a number that or greater than the first digit and lower than the last digit 正则表达式屏蔽除特定长度的最后两位之外的所有数字 - Regex to Mask all but Last Two Digits of a Number of Specific Length 将两位数年份转换为四位数字,还支持一位或两位数月份 - Convert two digit year to four digits and also support one or two digit month 计算数组中所有两位整数的和 - Calculate the sum of all two digits integers in an array 检查 Java 中两个三位数是否有相同的数字 - Checking if two three digit numbers have any of there digits that are the same in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM