Я должен написать метод «bisquare», который возвращает число бискваров в диапазоне чисел. Я думал, что понял, но когда я запускаю этот код, ничего не отображается, и мой ноутбук начинает крутиться как сумасшедший. Система никогда не говорит, что она закончилась.Это бесконечный цикл? Что я делаю не так? (Метод Java)
Вот мой код. Что я делаю не так? (Я также ищет решение проблемы, если я не настраивая это правильно.)
// An integer that is the sum of the squares of two other integers is called bisquare
// 5 is bisquare because it is 1*1 + 2*2
// 4 is bisquare because it is 0*0 + 2*2 (we can use 0 as one of our numbers)
// 8 is bisquare because it is 2*2 + 2*2 (we can use the same two numbers)
// 3 is not bisquare, 6 is not bisquare
//
// Given two int parameters, low and high, return the number of bisquares that
// fall between low and high (inclusive)
//
// EXAMPLES:
// low = 1, high = 6
// return 4
// 1, 2, 4, and 5 are bisquare. 3 and 6 are not
//
// low = 7, high = 7
// return 0
// 7 is not bisquare. that is the entire range we are checking.
public static int bisquare(int low, int high)
{
int count = 0;
boolean isBisquare = false;
for (int checkNum = low; checkNum < high; checkNum++) {
while (!isBisquare) {
for (int i = 0; i < high; i++) {
for (int j = 0; j < high; j++) {
if ((i*i) + (j*j) == low) {
count++;
isBisquare = true;
}
}
}
}
}
return count;
}
Каковы ваши входы? – Hackerdarshi
Что должен делать 'checkNum'? –
что использовать 'checkNum' – Sanjeev