Question

In: Computer Science

Write a program to multiply a polynomial with a given number. Code needed in java.

Write a program to multiply a polynomial with a given number.

Code needed in java.

Solutions

Expert Solution

Here is the solution to above problem in JAVA. Please read the code comments for more information

GIVE A THUMBS UP!!!

Explanation

1) First you need to take input from the user for the maximum degree for the polynomial

2) Than create an array of coffecient for each polynomial component in degree

3) After that input from user all the coffecients for the polynomial

4) Take input for the multiplication factor for the polynomial

5) Traverse the array and multiply coffecient array each element to the user input multiplication factor

6) Traverse the array and display the polynomial

JAVA CODE

import java.io.*;
import java.util.*;
public class Main
{
   public static void main(String[] args) {
   System.out.println("Enter the degree polynomial: ");
   int degree=0;
   Scanner sc = new Scanner(System.in);
   degree = sc.nextInt(); //take maximum degree as input
   //array to store coffecient
   Double coff[]= new Double [degree+1];
   for(int i=0;i<=degree;++i)
   {
   //take input for location i
   System.out.print("Enter coffecient of degree " + (degree-i) + ": ");
   coff[i] = sc.nextDouble();
   }
   //input for a number to multiply with
   System.out.print("Enter a number to multiply the polynomial: " );
   double multiply = sc.nextDouble();
   //multiply the coeficient array and print the answer
   for(int i=0;i<=degree;++i)
   {
   coff[i]= coff[i]*multiply;
   }
   //print the equation
   int x;
   for(x=0;x<degree;++x)
   {
   System.out.print(coff[x] + "x^" + (degree-x) + "+");
   }
   System.out.print(coff[x]);
   }
}
SCREENSHOT OF OUTPUT


Related Solutions

Write a program to multiply a polynomial with a given number. Code needed in java.
Write a program to multiply a polynomial with a given number. Code needed in java.
Write a program to multiply two polynomials. Code needed in Java.
Write a program to multiply two polynomials. Code needed in Java.
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
Must be written in JAVA Code Write a program that takes a whole number input from...
Must be written in JAVA Code Write a program that takes a whole number input from a user and determines whether it’s prime. If the number is not prime, display its unique prime factors. Remember that a prime number’s factors are only 1 and the prime number itself. Every number that’s not prime has a unique prime factorization. For example, consider the number 54. The prime factors of 54 are 2, 3, 3 and 3. When the values are multiplied...
Write a C program to calculate the number of fence panels needed over a given distance....
Write a C program to calculate the number of fence panels needed over a given distance. The fence must be created using two difference size panels which have a 2 foot length difference between them (ie. panels could be 2’ and 4’ or 3’ and 5’ or 5’and 7’). Your program should request the total length of the fence and the smaller panel's size. Your program will then calculate the length of the larger panel and output the number of...
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
P-3.36 Write a Java program for a matrix class that can add and multiply arbitrary twodimensional...
P-3.36 Write a Java program for a matrix class that can add and multiply arbitrary twodimensional arrays of integers.
Write code in MIPS ,read tow number from the user that do the following: 1- multiply...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply 2- Dividing 3- sum 4- average 5- minimum 6- maximum 7- print message to thank the user for using my program
Write a recursive a Java code that checks if a number is Palindrome. A palindrome number...
Write a recursive a Java code that checks if a number is Palindrome. A palindrome number is a number that reads the same from beginning to end and from end to beginning, in other words, a palindrome number remains the same when its digits are reversed. For example, 13431 is a palindrome number. 2332 is another one. (Note: Your algorithm should define and work with an integer number) The functionality of your code should be commented to explain what you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT