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
you are configuring a wireless connection on your home router. Because you live in an apartment complex, the level of security i
REY [17]

The question has the following answers attached

SSID

WEP

WPA

WPA2

Answer is WPA2

WEP is weak and remains highly vulnerable and is hardly used. There are simple and readily available tools that can be used to hack WEP encryption. If you have a choice to make between WPA and WPA2, I would suggest you choose WPA2 over its predecessor WPA. Both encryption methods support secure wireless internet networks from unauthorized access but WPA2 offers more protection. WPA2 uses more advanced and stronger encryption keys and support maximum protection for your connection.

4 0
3 years ago
Which are types of lines? Choose three answers.
alekssr [168]
Straight
Curvilinear
Rectilinear
7 0
3 years ago
Consider the following business environment.
ale4655 [162]

Answer:

Check the explanation

Explanation:

C-> OLAP systems allow users to analyze database information from multiple database systems at one time. The primary objective is data analysis and not data processing.

D-.Airlines use the Data Mining Techniques to improve Customer Service.

Kindly check the attached image below to see the step by step explanation to the question above.

7 0
3 years ago
What is computer science
solong [7]

Answer:

computer science is the study of the principles and use of computers.

Explanation:

8 0
3 years ago
Read 2 more answers
Please tell fast plzzzzz​
AURORKA [14]

Answer:

binary sequences

Explanation:

hahxvdavqkqbduvhsyax

7 0
3 years ago
Other questions:
  • A primary mailing list for new vulnerabilities, called simply __________, provides time-sensitive coverage of emerging vulnerabi
    10·1 answer
  • Investments in data networks, ip addresses, routers, and switches are ________ because of their impact on productivity, security
    14·1 answer
  • What Intel socket recommends the use of a liquid cooling system?
    12·1 answer
  • Which of these is an aggregator?
    5·2 answers
  • Which of the following is the most significant outcome of the formation of the SMPTE?
    6·2 answers
  • Which of the following statements is true?
    5·1 answer
  • Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. T
    9·1 answer
  • Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. U
    6·1 answer
  • Logan has developed an excellent presentation with interesting content. He received great feedback on the evaluation
    10·1 answer
  • What is the difference between MAC address and IP address?<br> Thanks in advance
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!