Question

(25 points) Factorize Write a String method factorize(int n, int m) that when given a positive integer n and an integer m, re
(25 points) Print Product Table Write a void method printProductTable(int n, int m) that when given two positive integers n a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

You did'nt specify which language so I did the coding in java.

Ques1-

Code:

File name: main.java

import java.util.Scanner;
public class Main
{
    //function to count number of factorization
    public static String factorize(int n,int m) {
        int count=0; //count variable to count number of times perfect division occurs
        while(m>=n)
        {
              count = count + 1;
              m /= n; //re-initializing variable m
        }
        String rev = Integer.toString(count); //converting integer to string
        return rev;
    }
    //driver function
        public static void main(String[] args) {
              Scanner scan = new Scanner(System.in);
              int number1 , number2;
        //taking inputs for m and n
        System.out.print("Enter first number(m) : ");
        number1 = scan.nextInt();
        System.out.print("Enter second number(n) : ");
        number2 = scan.nextInt();
        System.out.print("Number of times "+number2+" factors into "+number1+" : "+factorize(number2,number1)); //printing the result
        }
}

Output:

: C:\Users\rahul\Desktop>java band Enter first number : 100 on Enter second number : 5 Number of times 5 factors into 100 : 2

Ques2-

File name: Main.java

Code:

import java.util.Scanner;
public class Main
{
    //function to print tables in tabular format
    public static void printProductTable(int n,int m) {
      
      for(int i=1;i<=n;i++) //loop handles row part
      {
          for(int j=1;j<=m;j++)//loop handles column part
          {
            System.out.printf("%d\t",i*j); //print tables column wise when i value does'nt change 
                                           //and j value incrementing during each iteration
          }
        System.out.printf("\n"); 
      }
        
    }
    //driver funtion
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int row , col;
            //taking inputs for n rows and m columns
        System.out.print("Enter number of rows : "); 
        row = scan.nextInt();
        System.out.print("Enter number of columns : "); 
        col = scan.nextInt();
        printProductTable(row,col); //calling function
        }
}

Output:

input n 1 5 Enter number of rows : 7 Enter number of columns : 5 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 5 10 15 20 16 12 18 24 7 14

Add a comment
Know the answer?
Add Answer to:
(25 points) Factorize Write a String method factorize(int n, int m) that when given a positive...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted...

    Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted array a with n distinct integers, and an integer m. If there are two elements in the array that add to be m, the method returns True; if not, it returns False. You may assume that the elements in the array are all distinct. There are several ways to solve this problem! (and some solutions are worth more points than others!) For 6 points,...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of...

    Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of integers, declared to be "int** A," to the standard output. Each of the rows should appear on a separate line. Your input will be as follows with the first two values being the number of rows and columns respectively. HINT: This is best done with one for-loop nested within another Sample 1/0 1: Input: 3 2 1 2 3 4 Ол 6 Output: 12...

  • import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr =...

    import java.util.Scanner; public class Lab6d { public static void main(String[] args) {    Scanner scnr = new Scanner(System.in); // TODO: get user choice    // TODO: call printTable method passing choice as the parameter    } public static void printTable(int stop) { // TODO: print header    // TODO: loop to print table rows up to stop value    } Write a Java program where the main () method prompts the user to select an integer value between 1 and...

  • Short Answer Given the following class declaration for a binary string/integer pair (the binary n...

    ANSWER IN C++ Constructors Short Answer Given the following class declaration for a binary string/integer pair (the binary number, in the form of a string. should be the binary form of the integer): class binint public: int num; // Note this is an address! string *bin; // Note that this is an address! binint (int n); binint (string s); void convertitos(int n); void convertstoi(string s); II NOTE: you do not have to do anything // with this method you can...

  • public static List sumOfDistinctCubes(int n) Determine whether the given positive integer n can be expressed as...

    public static List sumOfDistinctCubes(int n) Determine whether the given positive integer n can be expressed as a sum of cubes of positive integers greater than zero so that all these integers are distinct. For example, the integer n = 1456 can be expressed as sum 11 3 + 5 3 . This method should return the list of these distinct integers as a list [11, 5] with the elements given in descending order. If n cannot be broken into a...

  • please solve CHALLENGE ACTIVITY 5.3.3: While loop: Insect growth. Given positive integer numinsects, write a while...

    please solve CHALLENGE ACTIVITY 5.3.3: While loop: Insect growth. Given positive integer numinsects, write a while loop that prints that number doubled without reaching 200. Follow each number with a space. After the loop, print a newline. Ex: If numInsects = 16, print: 16 32 64 128 1 #include <iostream> 2 using namespace std; von WN int main() { int numInsects; cin >> numInsects; // Must be >= 1 /* Your solution goes here */ 11 return 0; 12 }...

  • C++ A Program for Examining String (1) Ask the customer to type any string they like...

    C++ A Program for Examining String (1) Ask the customer to type any string they like and then print it to the console. Example: Type a sentence: The CIS161 Computer Science II course is so much fun! You typed: The CIS161 Computer Science II course is so much fun! (2) Write the remaining code for the CountOfLetters() function, which returns the number of characters in the string that was entered. To get full credit for this question, this should be...

  • "Controlling complexity is the essence of computer programming." Write a program that uses the C++ string...

    "Controlling complexity is the essence of computer programming." Write a program that uses the C++ string functionality to count the number of vowels in this phrase. Q7. Write a function bool xor(bool A, bool B) which returns the Exclusive OR of boolean input variables A and B. Test your function by printing out the full truth table of the function. Q8. Write a method swap(char_all, int i, int i) which swaps element i and element j of a given character...

  • Using Python write a program that reads an int N >= 0, then prints out each...

    Using Python write a program that reads an int N >= 0, then prints out each of the following patterns of *. If you do NOT use the string repetition operator * in either problem, you will earn 0.25 points of Extra Credit for each. Also, each pattern must be output via a single function call to the given named function with single parameter N. Examples for N==4 follow, with explanations of how the displayed diagram reflects this value of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT