我正在编写一个程序,要求用户输入总共十个不同时间的两个整数。第一个数字是第二个数字的倍数
接下来程序需要评估第一个整数是否是第二个整数的倍数。
如果第一个是第二个的倍数,那么程序应该输出“true”,如果不是那么它应该打印出“false”。
这里是我的代码:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int counter = 0; // Initializes the counter
System.out.printf("Enter first integer: "); // asks the user for the first integer
int number1 = input.nextInt(); // stores users input for the first integer
System.out.printf("Enter second integer: "); // asks the user for the second integer
int number2 = input.nextInt(); // stores the users input for the second integer
while (counter <= 10) // starts a loop that goes to 10
{
if (number1 & number2 == 0) // checks to see if number1 is a multiple of number2
System.out.print("true"); // if so then print out "true"
else
System.out.print("false"); // otherwise print out "false"
}
} // end class
某处沿着我的代码是打破了线。有没有人能够帮助,或者至少让我指向正确的方向?
使用'%'而不是'&'来检查number1是否是number2的倍数。 – 2015-04-04 20:54:18