943,844 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2219
  • Java RSS
Dec 1st, 2008
0

how to sort the output in descending

Expand Post »
alright..
i have a problem on how to sort the output
my code is here:
Java Syntax (Toggle Plain Text)
  1. public class Num7
  2. {
  3. public static void main(String[]args)
  4. {
  5. char[] ch;
  6. ch=new char[20];
  7. int i;
  8. for(i=0;i<ch.length;i++)
  9. System.out.print(i);
  10. }
  11. }
the output is simply:
Java Syntax (Toggle Plain Text)
  1.  
  2. 012345678910111213141516171819
all i want to do is to print first 19,18 and so on.
what should i modify?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beginner21 is offline Offline
16 posts
since Nov 2008
Dec 1st, 2008
0

Re: how to sort the output in descending

I feel you are posting your class assignments here one by one, while we do not have any problem outright with that there should be some effort from your side that comes across from your query/ problem. We haven't seen any such effort as yet from you on this post.
Read this before posting such queries here.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 1st, 2008
0

Re: how to sort the output in descending

ok,
this is my modify code:
Java Syntax (Toggle Plain Text)
  1.  
  2. public class Num7
  3. {
  4. public static void main(String[]args)
  5. {
  6.  
  7. char[] ch={'1','2','3','4','5','6','7','8','9'};
  8. int x,y,z;
  9. for(x=ch.length;x>0;x--)
  10. {
  11. System.out.print(x);
  12. }
  13. System.out.println();
  14. for(y=ch.length;y>0;y--)
  15. {
  16. System.out.print(y);
  17. }
  18. z=x*y;
  19. System.out.println("\nThe sum is: "+z);
  20. }
  21. }
it display the values i entered on the array backward,
and that's what i want,
the problem is the value of z,
z is always 0;
i cant figure out whats the problem,
can you help?
Last edited by beginner21; Dec 1st, 2008 at 3:17 am. Reason: code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beginner21 is offline Offline
16 posts
since Nov 2008
Dec 1st, 2008
0

Re: how to sort the output in descending

In Your code int x,y; are indexes of loop - for.
When loops finished x=0 and y=0.Multipy them result is 0.
You not using char[] ch={'1','2','3','4','5','6','7','8','9'}; table. More proper is declare table as int.
Analyse this:
java Syntax (Toggle Plain Text)
  1. public static void main(String[] args) {
  2.  
  3. int[] table = {9,8,7,6,5,4,3,2,1,0};
  4.  
  5. for (int x = table.length-1; x >= 0; x--) {
  6. System.out.print("x=");
  7. System.out.print(x);
  8. System.out.print(" ");
  9. System.out.print("table[x]=");
  10. System.out.print(table[x]);
  11. System.out.println();
  12. }
  13. System.out.println();
  14. }

quuba
Reputation Points: 123
Solved Threads: 106
Posting Pro
quuba is offline Offline
573 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Audio Analyzer
Next Thread in Java Forum Timeline: Hi/Lo code problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC