|
thanks I did ascending..
public class Main{
public static void main(String[] args) {
int[] value = {2,1,3,6,5};
System.out.println("Unsorted value");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
Arrays.sort(value);
System.out.println("sorted value ascending");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
}}
please tell how to do descending...
|
|
|
|
|
nt_virus wrote: please tell how to do descending...
Well I guess you need to look at the documentation for the Arrays.sort() method.
|
|
|
|
|
I read the documentation now, I didn't find descending. There is a way by Comparator .. but its lengthy .. Any other way .. please tell.
|
|
|
|
|
nt_virus wrote: There is a way by Comparator .. but its lengthy .. Any other way .. please tell.
You really think this[^] is lengthy? Or is it the reading of the documentation that's lengthy?
|
|
|
|
|
I tried that thing earlier but as I declared array as..
int[] value = {2,1,3,6,5}
So this line
Arrays.sort(value, Collections.reverseOrder()); giving error, red line under value, I don't understand why..
But now I declare array as ..
Integer[] value = {2,1,3,6,5}
It works....
package SortListOfNumbers;
import java.util.Arrays;
import java.util.Collections;
public class Main{
public static void main(String[] args)
{
Sorting srt = new Sorting();
srt.ascending();
srt.descending();
}
}
class Sorting{
public void ascending(){
int[] value = {2,1,3,6,5};
System.out.println("Sorting in ascending order");
System.out.println("Unsorted value");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
Arrays.sort(value);
System.out.println("sorted value ascending");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
}
public void descending(){
Integer[] value = {2,1,3,6,5};
System.out.println("Sorting in descending order");
System.out.println("Unsorted value");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
Arrays.sort(value, Collections.reverseOrder());
System.out.println("Sorted Descending");
for (int s : value)
System.out.print(s + " ");
System.out.println("\n");
}}
Please explain why is it happen so.. it bit strange for me.
and thanks a lot.
|
|
|
|
|
nt_virus wrote: Please explain why is it happen so.. it bit strange for me.
Probably because int is a simple type, but Integer is a class. I would suggest reading the Java documentation for a full description of the differences and what methods and interfaces they support.
|
|
|
|
|
I looked at your code, you need to read the error message which says The method sort(int[]) in the type Arrays is not applicable for the arguments (int[], Comparator < Object > ) so when you added the Integer you are solving the problem that was generated because Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
|
|
|
|
|
See further information below from Member 4277480.
|
|
|
|
|
Thanks a lot a lot to both of you guys.. You made my day..
|
|
|
|
|
* Hi everybody !
*
* Im using PDFBox to convert pdf to xhtml.
*
* Can anybody help me.
*
* In PDFBox source, there are no class pdf2xhtml but i found a class at
* http://lucene.apache.org/tika/xref/org/apache/tika/parser/pdf/PDF2XHTML.html
*
* How can i use it.
*
* Thanks and regards
|
|
|
|
|
We can generally help here with standard code, but when using third party components it is better to find if they have a forum and ask there.
This is the second time in a week when you have asked a question like this. It was kindly sugested to you to ask the people who wrote the component. What's different today?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
The users of this lib seem satisfied PDFToHTML[^]
Good Luck
|
|
|
|
|
Hello
i 'd like to know whether i can use .NET Framework inside Java or use .NET Framework classes and methodes in Java
Many Thanks
Thierry
|
|
|
|
|
Aside from J# I do not know of any interoperable software to do so. However, I use both in almost all the code I write. For example, If I want a feature that is not available in Java by default and is found in C# then I implement it using C# and make an executable and call it from Java. The calling varies depending on what I want some times I capture the output from the executable and process it in Java and other times I just let it do all the work.
|
|
|
|
|
|
You could convert the arrays to a list using Arrays.toList, then use Collections.indexOfSubList.
Or, if you want to do it yourself without converting the arrays to lists, take a look at the source for Collections.indexOfSublist to see how that does it, then implement your own version that operates directly in the arrays.
|
|
|
|
|
|
Snippet Example:
List<Integer> list = Arrays.asList(1,2,3,4,5);
System.out.println("List :"+list);
List<Integer> sublist = Arrays.asList(4,5);
System.out.println("SubList :"+sublist);
System.out.println("indexOfSubList: "+ Collections.indexOfSubList(list, sublist));
System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
if (Collections.indexOfSubList(list, sublist) != -1)
System.out.println(true);
else
System.out.println(false);
|
|
|
|
|
In your code you exit as soon as a mismatch is found rather then continuing to look in case the match occurs later.
Try this [untested]
static boolean hasSubsequence(int[] arr, int[] sub)
{
boolean matched = false;
for (int i=0;
i < arr.length-sub.length && !matched;
i++)
{
matched = true;
for (int j=0;
j <= sub.length && matched;
j++)
{
matched = (arr[i] == sub[j])
}
}
return matched;
}
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
try without the mistakes :
<pre> static boolean hasSubsequence(int[] arr, int[] sub) {
// no match for the outer loop
// this will exit when a match is found
boolean matched = false;
for (int i = 0; i <= arr.length - sub.length && !matched; i++) {
// start off matched for the inner loop
// this will exit when a mismatch is found
matched = true;
for (int j = 0; j < sub.length && matched; j++) {
matched = (arr[i+j] == sub[j]);
}
}
// at this point mayched is true if sub is inside arr
return matched;
}</pre>
Exercise for you is to work out WHY it was wrong....
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hey, I was wondering if there are any jobs over the internet tht involve me taking part in a project that I don't get paid for, for example an unpaid position that I could simply be given a task and then log off the internet and complete the task. If you would like more information just ask...
- Todd.
|
|
|
|
|
|
I enjoy answering Java board questions ![Smile | :)](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Member 4277480 wrote: I enjoy answering Java board questions
I've noticed that, you always offer very comprehensive answers. However, sometimes I think it does more good to get people to at least try and figure things out for themselves, so they may actually learn something.
|
|
|
|