1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Varvara68 [4.7K]
3 years ago
11

Write a function called factor that determines for a pair of integers whether the second integer is a factor of the first. The f

unction should take two integer arguments and return true if the second is a factor of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers. Hint: You will want to use modulus. Output: Enter in two integers: 8 4 4 is a factor of 8 Enter in two integers 9 4 4 is NOT a factor of 9
Computers and Technology
1 answer:
Aleks04 [339]3 years ago
3 0
<h2>Answer:</h2>

//import the Scanner class to allow for user's input

import java.util.Scanner;

//Declare the class and call it FactorClass

public class FactorClass {

   

   //Declare the function factor

   //It returns either true or false, therefore the return type is boolean

   //It receives two arguments - a and b

   public static boolean factor(int a, int b){

       

       //Check if a is divisible by b.

       //Return true if yes

       if(a % b == 0){

           return true;

       }

       

       //return false if a is not divisible by b

       return false;

   

   }  // End of method factor

   

   

   //The main method to test the function factor()

   public static void main(String[] args) {

       

       //Create an object of the Scanner class

       Scanner input = new Scanner(System.in);

       

       //Prompt the user to enter the pair of numbers

       System.out.println("Enter the pair of numbers (separated by a space)");

       

       //grab and store the first number in a variable

       int firstnum = input.nextInt();

       

       //grab and store the second number in another variable

       int secondnum = input.nextInt();

       

       

       //With the variables, call the factor() method

       //If it returns true, print the adequate message

       if(factor(firstnum, secondnum)){

           System.out.println(secondnum + " is a factor of " + firstnum);

       }

       

       //If it returns false, print the adequate message

       else{

           System.out.println(secondnum + " is NOT a factor of " + firstnum);

       }

   

 }            // End of main method

   

}    // End of class declaration

==============================================================

<h2>Sample Output 1:</h2>

>> Enter the pair of numbers  separated by a space

8 4

>> 4 is a factor of 8

==============================================================

<h2>Sample Output 2:</h2>

>> Enter the pair of numbers  separated by a space

9 4

>> 4 is NOT a factor of 9

==============================================================

<h2>Explanation:</h2>

The above code has been written in Java and it contains comments explaining every segment of the code. Kindly go through the comments for better understanding of the code.

For simplicity, the code is re-written as follows with little or no comments;

import java.util.Scanner;

//Declare the class and call it FactorClass

public class FactorClass {

   

   public static boolean factor(int a, int b) {

       if(a % b == 0){

           return true;

       }

       

       //return false if a is not divisible by b

       return false;

   

   }  // End of method factor

   

   

   //The main method to test the function factor()

   public static void main(String[] args) {

       

       //Create an object of the Scanner class

       Scanner input = new Scanner(System.in);

       

       //Prompt the user to enter the pair of numbers

       System.out.println("Enter the pair of numbers (separated by a space)");

       

       //grab and store the first number in a variable

       int firstnum = input.nextInt();

       

       //grab and store the second number in another variable

       int secondnum = input.nextInt();

       

       

       if(factor(firstnum, secondnum)){

           System.out.println(secondnum + " is a factor of " + firstnum);

       }

       

       else{

           System.out.println(secondnum + " is NOT a factor of " + firstnum);

       }

    }

   

}

You might be interested in
How do you go about placing a picture in your question?
rodikova [14]

when you are asking your question you can click on the link down at the bottom and when it pops up all your files click the one who want to send

plz mark brainliest lol seemed like an easy question but i need them to rank up so yea lol

6 0
2 years ago
Read 2 more answers
The good example of pivoting is changing thedimensions along the axis.? True? False
ollegr [7]

Answer:

False

Explanation:

The good example of pivoting is NOT changing the dimensions along the axis.

5 0
3 years ago
Which of the following programming languages
trapecia [35]

Answer:

I think

BASIC programming language

5 0
2 years ago
Read 2 more answers
Which of the following parts can be stored outside without contaminating the environment? A) Windshields B) Batteries C) Brake m
Lilit [14]
Windshields can be stored outside without contaminating the environment

4 0
3 years ago
What term specifies how information systems resources should be used and how they should work together?
jarptica [38.1K]

Answer:

b.Information systems architecture

Explanation:

Information System Architecture defines a system in terms of its resources and how they interact with each other. Some aspects of the Information System Architecture include the data that is managed by the system and the architecture of the application software. Another aspect is configuration, which involves the hardware architecture of the system. The organization of the system takes a look at the maintenance of the system while the communication aspect architecture looks at the networks that link the different resources e.g topology diagrams.

6 0
3 years ago
Other questions:
  • I need help with this​
    7·1 answer
  • Write a program that calculates the occupancy rate for ahotel. The program should start by asking the user how many floorsthe ho
    6·1 answer
  • What are network operating systems
    8·1 answer
  • Which decimal number is equivalent to this hexadecimal number?<br> F8
    6·2 answers
  • What is the difference between a surge and a spike?
    5·1 answer
  • Which key combination should you use
    9·2 answers
  • Explain program and programming with two examples of each<br>Help​
    12·1 answer
  • The four differences between binary and denary​
    13·1 answer
  • Answered
    10·1 answer
  • What to do if you click on a phishing link on iphone
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!