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
An IT suspects that an unauthorized device is connected to a wireless network. This is a result of pastry sharing on a device br
telo118 [61]

Answer:

3. WiFi Protected Access 2

Explanation:

Given that Wi-Fi Protected Access 2 often referred to as WAP 2 is a form of computer security or privacy measure to ensure that Wireless networks are furnished with powerful security of data network access control.

Hence, when a user employed or utilize WPA2. It gives such a user a high degree of maximum certainty of controlling the users that can have access to his wireless network.

Hence, in this case, what is put in place to stop such activity is Wi-Fi Protected Access 2

6 0
3 years ago
Some of the latest smartphones claim that a user can work with two apps simultaneously. This would be an example of a unit that
SIZIF [17.4K]

Answer:

MULTITASKING OS

Explanation:

MULTITASKING OPERATING SYSTEM is an operating system that enables and allow user of either a smartphone or computer to make use of more that one applications program at a time.

Example with MULTITASKING OPERATING SYSTEM smartphones user can easily browse the internet with two applications program like chrome and Firefox at a time or simultaneously

Therefore a user working with two apps simultaneously is an example of a unit that uses a MULTITASKING OS.

3 0
2 years ago
Joe has just started the Security Module. He wants to get through it as quickly as possible and take the Quiz. As he clicks thro
Scorpion4ik [409]

Answer:

Joe should read the explanatory text and complete the learning activities.

Explanation:

Given

See attachment for options

Required

Best strategy to get through the module

First off, rushing through the activities and taking guess for each question (as suggested by (a)) will not help him;

He may complete the activities but sure, he won't learn from the module.

Also, reading through the units without completing the activities is not an appropriate method because Joe will not be able to test his knowledge at the end of the module.

The best strategy to employ is to read through the units and complete the activities, afterwards (option (b)).

4 0
2 years ago
Specification of database requirements falls under which category of database​ administration?
enot [183]
Specification of database requirements falls under which category of database​ administration?

b. development
3 0
3 years ago
3. How are you able to create photographs differently than 100 years ago?
Agata [3.3K]

Answer:

it willbe black and white

Explanation:

3 0
2 years ago
Read 2 more answers
Other questions:
  • 2. You have classes to represent different shapes (see below). You realize you can benefit from inheritance and polymorphism by
    13·1 answer
  • What information is required for a complete citation of a website source?
    8·2 answers
  • The title of a Web page is the text that appears on the title bar and taskbar of the browser window. *
    13·1 answer
  • Once your hard drive is installed what needs to be done to the drive and what do these two tasks do
    12·1 answer
  • A Narrative Statement illustrates how your life will look when you reach a goal.
    15·2 answers
  • Why is it so important that you know how much traffic dfs replication requires?
    13·2 answers
  • In which job role would a course in 3D modeling help with professional career prospects?
    9·2 answers
  • Which of the following contributes to your active digital footprint
    12·2 answers
  • What are the first letters of each of the 3 main colors in javaScript? (seperate with commas)
    9·1 answer
  • A server is handling thousands of simultaneous connections, and proxying requests to another service. Which concurrency model is
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!