Check If A Number Is A Multiple Of Another Number in Java

Question : (Multiples) Write an application that reads two integers, determines whether the first is a multiple of the second and prints the result. [Hint: Use the remainder operator.]

Check If A Number Is A Multiple Of Another Number in Java

/*
 *       Filename:  Multiples.java
 *
 *    Description:  Exercise 2.26 - Multiples
 *
 *        @Author:  Bilal Tahir Khan Meo
 *        Website: https://codeblah.com
 *
 * =====================================================================================
 */
import java.util.Scanner;

public class Multiples{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter two space separated integers: ");
        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.printf("%d is%sa multiple of %d\n", x, (x % y == 0 ? " " : " not "), y);
    }
}

Method 2 : Check If A Number Is A Multiple Of Another Number in Java

/**
 *
 * @Author:  Bilal Tahir Khan Meo
 * Website: https://codeblah.com
 *
 * Exercise 2.26 - Multiples
 * This Program Determines Whether The First Number Is A Multiple Of The Second Number
 *
 */
 
import java.util.Scanner;
 
public class Ex02_26 {
    public static void main (String [] args) {
 
 Scanner numbers = new Scanner (System.in);        
 
 int num1;
        int num2; 
        int check;
         
        System.out.print ("Enter First Number: ");
        num1 = numbers.nextInt();
        System.out.print ("Enter Second Number: ");
        num2 = numbers.nextInt();
        check = num2%num1;
         
        System.out.println ();
         
        if (check == 0)
            System.out.printf ("The Number %d is a multiple of %d", num1, num2);
        else
            System.out.printf ("The Number %d is not a multiple of %d", num1, num2);
 
    }
}