Program To Check If A Number Is A Multiple Of Another Number

The program below is the answer to Deitel's Java How to Program (9th Edition) Chapter 2 Exercise 2.26.

Question: 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.]

```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.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);

}
}
```

1 comment:

DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.

Thanks.