Multiples

Date completed: 16/06/2017

This program asks the user to input two integers and determines if the first integer is a multiple of the second.

The Code Used

                
/*
 * This application  reads in two integers, determines whether the first is a
 * multiple of the second and prints the result.
 *
 **/

package multiples;

import java.util.Scanner; // program uses class scanner

public class Multiples {

    public static void main(String[] args) {
       
        // create Scanner to obtain input from command window.
	Scanner input = new Scanner(System.in);
		
	// Variable declarations
	int number1; 		// 1st number to be tested
        int number2; 		// 2nd number to be tested
        
        System.out.print("Enter the 1st number: "); // prompt for the 1st integer
	number1 = input.nextInt();                  // read the in the 1st integer
        
        System.out.print("Enter the 2nd number: "); // prompt for the 2nd integer
	number2 = input.nextInt();                  // read the in the 2nd integer
        
        // If after dividing the second number by the first number and there is 
        // no remainder then the first number entered is a multiple of the second.
        if(number2%number1 == 0){
            System.out.printf("The 1st number entered is a multiple of the second.\n");
        }else{
            System.out.printf("The 1st number entered is not a multiple of the second.\n");
        }
    }
}	
                
            

Some screen prints

Description Screen Print Out
The output as seen in Netbeans when the 1st number entered is a multiple of the second. multiple
The output as seen in Netbeans when the 1st number entered is not a multiple of the second. not multiple