# Multiples

Page 1 of 1

## 7 Replies - 628 Views - Last Post: 16 July 2010 - 01:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=181818&amp;s=89d5023978b83fb949907eb994df7c12&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Vincent53

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 07-May 10

# Multiples

Posted 16 July 2010 - 08:17 AM

Hello all,

What I am trying to do is find out what is the formula for determining whether one number is a multiple of the other. I have been at this for awhile and the closest that I came so far is if number1 % number2 == 0. Would this be the correct java statement or not?
Is This A Good Question/Topic? 0

## Replies To: Multiples

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11785
• Posts: 44,289
• Joined: 27-December 08

## Re: Multiples

Posted 16 July 2010 - 08:18 AM

Yes- this is the correct formula.

### #3 eZACKe

• Garbage Collector

Reputation: 120
• Posts: 1,278
• Joined: 01-June 09

## Re: Multiples

Posted 16 July 2010 - 08:20 AM

Indeed.

Modulus is used to get a remainder when divided. If the remainder is 0 when one number is divided by another, the you have yourself a multiple.

### #4 Vincent53

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 07-May 10

## Re: Multiples

Posted 16 July 2010 - 11:34 AM

Hello again,

I am trying to write a program that will determine whether one number is a multiple of the other. I have the formula correct I think but I am having a problem getting it to work and calculate. I am a tyotal novice at this. Below is as far as I have gotten.

```  /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author Vincent53
*/
public class PartB
{
public static void main  ( String args [])
{
// variable declarations
int num1;           //  first number to compare
int num2;           //  second number to compare
int num3 =0;   //  variable to hold multiple

// create Scanner to capture input from console
Scanner input = new Scanner(System.in);

// get user input, num1 and num2
System.out.print("Enter first number: ");
num1 = input.nextInt();
System.out.print("Enter second number: ");
num2 = input.nextInt();

// Calculate multiple
if ( num1 % num2 == num3 );

}
}

```

Iknow that Iam missing something but I do not know what it is. Thank You for your help.

Edited by macosxnerd101: Welcome to DIC! Please remember to post your code using code tags, like so: .

### #5 irmoathlete

Reputation: -1
• Posts: 98
• Joined: 09-July 10

## Re: Multiples

Posted 16 July 2010 - 11:40 AM

hey make sure when you post your code put it in between code tags please.
```System.out.println("like this please");

```

when you want to see if you have a multiple of another, just check if your first number modded by your second is 0. if it is then its a multiple.

### #6 sh1n3

Reputation: 24
• Posts: 164
• Joined: 22-April 10

## Re: Multiples

Posted 16 July 2010 - 11:41 AM

There is no need for num3 and I think it's always the greater number mod lesser number, just try :
```int big=(num1>num2)?num1:num2;
int small=(num1>num2)?num2:num1;

if(big%small==0) {
}
```

### #7 eZACKe

• Garbage Collector

Reputation: 120
• Posts: 1,278
• Joined: 01-June 09

## Re: Multiples

Posted 16 July 2010 - 11:42 AM

Your code is completely correct except for right here:
```if ( num1 % num2 == num3 );

```

You do not want the semicolon there. If the statement is true then you are probably going to want to let the user know somehow. If it's not true, you should also tell the user.

So follow this format:
```if(some expession)
{
System.out.println("yes");
}
else{
System.out.println("no");
}

```

Something like that should do the trick!

This post has been edited by eZACKe: 16 July 2010 - 11:44 AM

### #8 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11785
• Posts: 44,289
• Joined: 27-December 08

## Re: Multiples

Posted 16 July 2010 - 01:41 PM

Duplicate topics merged. Please avoid duplicate posting.