|
Re: please help me on this question
|
Posted: Aug 5, 2005 4:59 AM
|
|
First off please put the approriate tags around your code to make it easier on the eye for us guys responding.
The code simply check that array p and q have the same words (equivalent by spelling - case sensitive). for every word in p, q holds an equivalent.
On hitting reply your code seems fine, but when I read it off the web it looked like you made an errored call (it doesn't read the [] tags
if(!look (p,q))
Anyways, again please format your code properly.
> The code is as follows: >
> // class Meth 1 > class Meth1 > { > public static boolean words(String[] p, String[] q) > { > boolean flag = true; > > if (p.length != q.length) > flag = false; > else > for (int i=0; i<p.length;i++) > { > if (!look (p,q[i])) > flag = false; > break; > } > return flag; > }//words > > public static boolean look (String[] p, String w) > { > boolean flag = true; > String[] temp = new String[6]; > > for ( int i= 0; i<p.length;i++) > if (!p[i].equals(w)) > { > flag = false; > > } > return flag; > } > > public static void sort(String[] array, int len) > { > int a, b; > String temp; > int highSubscript = len - 1; > for (a = 0; a < highSubscript; ++a) > for (b = 0; b < highSubscript; ++b) > if (array[b].compareTo(array[b+1]) > 0) > { > temp = array[b]; > array[b] = array[b+1]; > array[b+1] =temp; > } > } > > > } > > public class Sorting extends Meth1 > { > public static void main(String[] args) > { > boolean w_flag; > > int x; > > String[] eng = {"cast", "static", "thread", "make", > e", "void", "import"}; > String word = "master"; > > System.out.println("Before sort"); > for (x = 0; x < 5; ++x) > System.out.println(eng[x]); > > sort(eng, eng.length); > > System.out.println("\nAfter sort"); > for (x = 0; x< 5; ++x) > System.out.println(eng[x]); > > w_flag = look(eng, word); > } > } >
> I'm quite confused of what the method "words" is doing. > > I think that it is performing a count on an > array(characters) which is entered but i'm not sure. > > Could you please help me. > > Thanks
|
|