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
Which type of network consists of multiple Windows computers that share information, but no computer on the network serves as an
Alexxandr [17]

The type of network that consists of multiple Windows computers that share information is peer-to-peer. In this network, the computer serves as an authoritative source of user information.

<h3>Peer-to-peer computer networks</h3>

A peer-to-peer (P2P) network can be defined as a type of network where the computer acts as a source of user information.

In P2P, a cluster of different computers are linked and they have the same permissions for processing data in the network.

This type of computer network (peer-to-peer computer network) has been created to serve and/or receive data.

Learn more about peer-to-peer computer networks here:

brainly.com/question/1172049

7 0
2 years ago
Gabe wants to move text from one document to another document. He should _____.
Lorico [155]
Copy and paste the text
8 0
3 years ago
Read 2 more answers
Identify why research and a clearly written problem statement are important. Select all that apply. They result in a clear and c
saveliy_v [14]

Answer:

They result in a clear and concise statement of the problem

They ensure that all stakeholder needs are considered.

They result in a document that is easy to understand

Explanation:

Problem statement are very vital in research they are key notes that tells what the research is all about and solution it will provide. They are key notes to understand a research and the knowledge gap the research is filling.

Problem statement is a guide through which solution are measured, it gives a clear direction of what the research is all about.

Problem statement are usually easy to understand, they are written in ways that everyone who picks the paper up can understand why the research was conducted.

All this are why a problem statement is important.

7 0
3 years ago
Read 2 more answers
You write a short story, but you want to make sure your work is protected before you post it online. What should you do to help
Mars2501 [29]
Make sure you but no copyright, author, and date of publication, that may help.
8 0
3 years ago
LEARNING TASK 3 about: REAMING THE RIGID STEEL CONDUIT.
devlian [24]

Answer:

1.I have learned that my teacher is a good teacher

2.I have realized that my name is beautiful

Explanation:

thats right? hope it's help you heart me and please give brainlesst

3 0
2 years ago
Other questions:
  • Mike is reading about machine-dependent programming languages. Which languages are machine-dependent programming languages?
    11·1 answer
  • 01010010 01100101 01100001 01101100 00100000 01101101 01110101 01110011 01101001 01100011 00100000 01110100 01101001 01101100 01
    5·2 answers
  • Stealing passwords by using software code to run through various password schemes with numbers, symbols, capital letters, and ch
    6·1 answer
  • A(n) _________ is a computer system which is part of a larger system which performs a dedicated function.
    8·1 answer
  • What is data Communications​
    11·2 answers
  • In his digital portfolio, Ben wants to locate each work he created. Where can he list details about the work in his digital port
    7·2 answers
  • Overview
    7·1 answer
  • Technology changes rapidly. Do you think the development of new technology will slow down at some point? At some point will cons
    12·1 answer
  • 8.11 LAB: Filter and sort a list
    8·1 answer
  • Besides a backup technician, who else would have encrypted backup passwords?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!