Results 1 to 19 of 19
Thread: sorting
- 09-30-2008, 01:59 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
sorting
/*INPUT TWO STRING ARRAYS AND SORT THEM*/
class manyarrays
{
public void main(String arr1[],String arr2[])
{
int len=arr1.length;
int len2=arr2.length;
String arr3[]=new String [l];
String arr4[]=new String [l1];
manyarrays obj=new manyarrays();
c[]=obj.sort(ab[],l);//error(not a statement)
d=obj.sort(b[],l1);
for(int z=0;z<l;z++)
System.out.println(arr3[z]);
for(z=0;z<l1;z++)
System.out.println(arr4[z]);
}
String sort(String a[] ,int l)
{
int z,j;
String temp;
for(z=0;z<l;z++)
{
for(j=0;j<l-1;j++)
{
if(a[j].compareTo(a[j+1])>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
return a;
}
}
/*
variable z--loop
j--loop
len--length of first inputed array
len2-length of second inputed array
*/
- 09-30-2008, 02:11 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You don't have define c[] in your code.
Instantiation of arr3 and arr4 is wrong, length is not define.
Variable b is not define in your code.
Two for loops are incorrect.
- 09-30-2008, 02:23 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
/*INPUT TWO STRING ARRAYS AND SORT THEM*/
class manyarrays
{
public void main(String arr1[],String arr2[])
{
int len=arr1.length;
int len2=arr2.length;
String arr3[]=new String [len];
String arr4[]=new String [len2];
manyarrays obj=new manyarrays();
arr3[]=obj.sort(arr1[],l);//error(not a statement)
arr4[]=obj.sort(arr2[],l1);
for(int z=0;z<l;z++)
System.out.println(arr3[z]);
for(z=0;z<l1;z++)
System.out.println(arr4[z]);
}
String sort(String a[] ,int l)
{
int z,j;
String temp;
for(z=0;z<l;z++)
{
for(j=0;j<l-1;j++)
{
if(a[j].compareTo(a[j+1])>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
return a;
}
}
/*
variable z--loop
j--loop
len--length of first inputed array
len2-length of second inputed array
*/
stilll error is there
- 09-30-2008, 02:46 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes it is. Still you don't have correct some points. In that statement l is not define.
- 09-30-2008, 02:50 PM #5
Eranga,
How do you see the errors? I don't see where the OP has posted them.
Ok I just saw them. They were hidden in the code. I guess I need better glasses to see them. A bigger banner like:<<<<<<<<<<<<<<<<<< HERE <<<<<<<<<<<<<<<<<
would make it easier.
- 09-30-2008, 03:13 PM #6
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
solution to my error
- 09-30-2008, 03:14 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
/*INPUT TWO STRING ARRAYS AND SORT THEM*/
class manyarrays
{
public void main(String arr1[],String arr2[])
{
int len=arr1.length;
int len2=arr2.length;
String arr3[]=new String [len];
String arr4[]=new String [len2];
manyarrays obj=new manyarrays();
arr3[]=obj.sort(arr1[],len);//error(not a statement)
arr4[]=obj.sort(arr2[],len2);
for(int z=0;z<l;z++)
System.out.println(arr3[z]);
for(z=0;z<l1;z++)
System.out.println(arr4[z]);
}
String sort(String a[] ,int l)
{
int z,j;
String temp;
for(z=0;z<l;z++)
{
for(j=0;j<l-1;j++)
{
if(a[j].compareTo(a[j+1])>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
return a;
}
}
/*
variable z--loop
j--loop
len--length of first inputed array
len2-length of second inputed array
*/
<<<<<<<<<<<<<<<<stilll same error is there>>>>>>>>>>>>>
- 09-30-2008, 03:30 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 09-30-2008, 03:34 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 09-30-2008, 05:13 PM #10
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
yes you are right but it cannot return a array also
so what can i do
- 10-01-2008, 03:46 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Why you can't return an array from that method? Did you try, and get any errors? If so, what the error message says?
- 10-01-2008, 06:35 AM #12
This smells like homework to me. Part of learning is learning how to debug
- 10-01-2008, 07:31 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And learning fundamentals. Seems he doesn't know about returning values from a method.
- 10-01-2008, 09:11 AM #14
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
/*INPUT TWO STRING ARRAYS AND SORT THEM*/
class manyarrays
{
public void main(String arr1[],String arr2[])
{
int len=arr1.length;
int len2=arr2.length;
String arr3[]=new String [len];
String arr4[]=new String [len2];
manyarrays obj=new manyarrays();
arr3=obj.sort(arr1,len);
arr4=obj.sort(arr2,len2);
for(int z=0;z<l;z++)
System.out.println(arr3[z]);
for(z=0;z<l1;z++)
System.out.println(arr4[z]);
}
String sort(String a[] ,int l)
{
int z,j;
String temp;
for(z=0;z<l;z++)
{
for(j=0;j<l-1;j++)
{
if(a[j].compareTo(a[j+1])>0)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
return;
}
}
returning array
error incompatible data types
found java.lang.String but expected java.lang.string[]
- 10-01-2008, 10:49 AM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You have nothing is returning here.
Java Code:return;
- 10-01-2008, 11:04 AM #16
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
then what is the solution
- 10-01-2008, 11:45 AM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you want to return a string you should return that, if you want to return an array, you should do that.
Do you know how to write a method in Java and return a value? Seems to me you don't.
- 10-02-2008, 10:10 AM #18
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
how can we return an array
- 10-02-2008, 10:30 AM #19
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You should learn how to methods are define in Java.
Java Code:public static int[] method_name() { int[] a = new int[5]; return a; }
Similar Threads
-
CompilationUnit sorting
By rhub in forum EclipseReplies: 0Last Post: 09-18-2008, 01:22 PM -
Sorting CachedRowset
By Sayed in forum Advanced JavaReplies: 0Last Post: 07-18-2008, 12:14 PM -
sorting problem...
By mark-mlt in forum New To JavaReplies: 4Last Post: 04-17-2008, 02:15 PM -
sorting problem
By mcal in forum New To JavaReplies: 1Last Post: 02-14-2008, 08:13 AM -
sorting JTable
By mansi_3001 in forum Advanced JavaReplies: 3Last Post: 08-10-2007, 06:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks