Java I';我正在写一个关于模数的程序

Java I';我正在写一个关于模数的程序,java,Java,我需要帮助。我想写一个程序,根据你写的值,它显示的是真还是假取决于,如果没有提醒,7的值的除法。 我写了这篇文章,但它不能正常工作: import java.util.Scanner; public class ex05 { public static void main(String[] args) { Scanner sc = new Scanner (System.in); System.out.println("Please enter a value

我需要帮助。我想写一个程序,根据你写的值,它显示的是真还是假取决于,如果没有提醒,7的值的除法。 我写了这篇文章,但它不能正常工作:

import java.util.Scanner;

public class ex05 {

    public static void main(String[] args) {

    Scanner sc = new Scanner (System.in);   
    System.out.println("Please enter a value:");
        int  x = sc.nextInt();

        int a = x / 7;

        if (x % a == 0) 
        {
            System.out.println("true");
        }
        else {
            System.out.println("false");
        }
    }
}

我想你明白了,没有解释。简单的数学

public class ex05 {

public static void main(String[] args) {

Scanner sc = new Scanner (System.in);   
System.out.println("Please enter a value:");
    int  x = sc.nextInt();


    if (x % 7 == 0) 
    {
        System.out.println("true");
    }
    else {
        System.out.println("false");
    }
}
}
(
a%b

%是模数运算符,它在将
a
除以
b
后检查剩余值
)不需要使用
a
%
运算符给出剩余值。使用
/
是没有用的。做

int  x = sc.nextInt();

if (x % 7 == 0){
    System.out.println("true");
}else{
    System.out.println("false");
}
或者只是

System.out.println(x % 7 == 0);

只要做
if(x%7==0)
就行了,不需要使用
a
。它现在可以工作了。谢谢:)更简单,
System.out.println(x%7==0)