178k views
1 vote
1. Write a method isMultiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. [Hint: Use the remainder operator.] Incorporate this method into an application that inputs a series of pairs of integers (one pair at a time) and determines whether the second value in each pair is a multiple of the first This is a sample run of your program: Enter·one·number:7↵ Enter·a·second·number:49↵ 49·is·a·multiple·of·7↵ Do·you·want·to·enter·another·pair(y/n)?Enter·one·number:7↵ Enter·a·second·number:28↵ 28·is·a·multiple·of·7↵

User BenceL
by
6.5k points

1 Answer

2 votes

Answer:

see explaination for code

Step-by-step explanation:

Implement using JAVA

import java.util.Scanner;

public class Multiples {

public static boolean isMultiple(int first, int second){

if(second%first == 0)

return true;

else

return false;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(true){

System.out.print("Enter one number: ");

int first = sc.nextInt();

System.out.print("Enter a second number: ");

int second = sc.nextInt();

if(isMultiple(first, second))

System.out.println(second+" is multiple of "+first);

else

System.out.println(second+" is not multiple of "+first);

System.out.print("Do you want to enter another pair(y/n)? ");

char c = sc.next().charAt(0);

if('y' != Character.toLowerCase(c))

break;

}

}

}

/*

Sample run:

Enter one number: 7

Enter a second number: 28

28 is multiple of 7

Do you want to enter another pair(y/n)? y

Enter one number: 8

Enter a second number: 24

24 is multiple of 8

Do you want to enter another pair(y/n)? y

Enter one number: 4

Enter a second number: 2

2 is not multiple of 4

Do you want to enter another pair(y/n)? n

*/

User Nitzanj
by
6.9k points