The Artima Developer Community
Sponsored Link

Java Answers Forum
please help me on this question

1 reply on 1 page. Most recent reply: Aug 5, 2005 4:59 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
sabrina

Posts: 1
Nickname: rina
Registered: Aug, 2005

please help me on this question Posted: Aug 5, 2005 3:04 AM
Reply to this message Reply
Advertisement
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))
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.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.compareTo(array[b+1]) > 0)
{
temp = array;
array = 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", "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


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: please help me on this question Posted: Aug 5, 2005 4:59 AM
Reply to this message Reply
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++)
&gt; {
&gt; if (!look (p,q[i]))
&gt; flag = false;
&gt; break;
&gt; }
&gt; return flag;
&gt; }//words
&gt;
&gt; public static boolean look (String[] p, String w)
&gt; {
&gt; boolean flag = true;
&gt; String[] temp = new String[6];
&gt;
&gt; for ( int i= 0; i<p.length;i++)
&gt; if (!p[i].equals(w))
&gt; {
&gt; flag = false;
&gt;
&gt; }
&gt; return flag;
&gt; }
&gt;
&gt; public static void sort(String[] array, int len)
&gt; {
&gt; int a, b;
&gt; String temp;
&gt; int highSubscript = len - 1;
&gt; 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

Flat View: This topic has 1 reply on 1 page
Topic: java.security.AccessControlException Previous Topic   Next Topic Topic: help me in selecting project

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use