willl smith

Greenhorn
+ Follow
since Dec 03, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by willl smith

could someone please explain what is going on here:

int sum = 0;
int k = 7146;
do {
sum = sum + k % 10;
k = k / 10;
} while (k > 0);
System.out.println (sum);
19 years ago
convert code into a method with header:

I just wrote a code to multiply two polynomials together but I dont know what it means to convert it into a method with a header, thanks..

public class MultPoly // tests multiplication of two polynomials

{
public static void main (String[] args)
{

int[] p = {2, 5, 3, 4};
int m = p.length - 1; // degree of p
int[] q = {4, 6, 8};
int n = q.length - 1; // degree of q
int[] r = new int [m + n + 1];// This will store the product.

for (int i = 0; i < p.length; i++)
{ //increments leading coefficient
for (int x=0; x < q.length; x++)
{
r[i + x] += (p[i] * q[x]);
}
}//for

int k;

for (k = 0; k < r.length - 1; k++)
{
System.out.print (r[k] + ", ");
}
System.out.println (r[k] + "."); // prints out final digit of polynomial

}//main

}//class
19 years ago