所以,我想找出 1 到 100 之间的哪些数字可以被 3 和 7 整除。我让它工作了,除了其中一个数字。出于某种原因,3 % 3 给了我 3 作为余数,但 6 % 3 给了我 0。这是我的代码:
public class factors
{
public static void main(System args[])
{
//Variables
int integer, remainder;
//Displays header
System.out.print("Integers less than 100 that are \nevenly divisible by 3 or 7");
//Loops through each integer
for (integer = 1; integer <= 100; integer++)
{
remainder = integer % 3; //determines if 3 is a factor
if (remainder == 0) //displays integer
{
System.out.println(integer + " is divisible by 3");
}
remainder = integer % 7; //determines if 7 is a factor
if (remainder == 0) //displays integer
{
System.out.println(integer + " is divisible by 7");
}
}
}
}有谁知道为什么这对数字 3 不起作用?