Lightbulbhw help!

Posts 1–3 of 3 · Page 1 of 1
hw help!
Well let's say I've been missing a couple classes and I need help understanding some of this stuff. Anyone can help me get started and such, itll be great.

Create a class called Character. The class should have the following public member functions:

A function called compare, that accepts as parameters two arrays (of type char), and one size variable (of type int) that indicates the size of both arrays. The function should determine if the contents of the two arrays are the same, then return a value (of type bool) depending on whether the contents are the same (true) or not (false).
if you want it in java.. I'll type it here (sorry, I don't have an eclipse on my PC so I can't copy-paste it from there)
Code:
public class Character
{
//if you need it to be an object - this is the building function
public Character ()
{

}
//if you don't need to create an object, you may want to type in a 'static' like this
//public static boolean compare(char[] a,char[] b,int slots), slots stands for a.length (or b.length, they're the same)
public boolean compare(char[] a,char[] b,int slots)
{
if(slots==0)
{
return true;
}
else if(a[slots-1]==b[slots-1])
         return true&&compare(a,b,slots -1);
return false;
}
}
that's just a recursive way I found which is not too hard to write and understand
hope it'll help you (:
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Need help?