Java if statement check factor

Question

We would like to use if statement to check that is one input is the factor of another input.

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      /* w  w w .  ja v  a  2  s. c o m*/
      Scanner input = new Scanner(System.in);
      int x, y;
      
      System.out.println("Enter two integers:");
      x = input.nextInt();
      y = input.nextInt();
      
      //your code here
      
      input.close();
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      
      Scanner input = new Scanner(System.in);
      int x, y;
      
      System.out.println("Enter two integers:");
      x = input.nextInt();
      y = input.nextInt();
      
      if (x % y == 0)
        System.out.println("yes");
      if (x % y != 0)
        System.out.println("no");
      
      input.close();
    }
}



PreviousNext

Related