how to sort the output in descending

Reply

Join Date: Nov 2008
Posts: 8
Reputation: beginner21 is an unknown quantity at this point 
Solved Threads: 0
beginner21 beginner21 is offline Offline
Newbie Poster

how to sort the output in descending

 
0
  #1
Dec 1st, 2008
alright..
i have a problem on how to sort the output
my code is here:
  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:
  1.  
  2. 012345678910111213141516171819
all i want to do is to print first 19,18 and so on.
what should i modify?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 822
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: how to sort the output in descending

 
0
  #2
Dec 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: beginner21 is an unknown quantity at this point 
Solved Threads: 0
beginner21 beginner21 is offline Offline
Newbie Poster

Re: how to sort the output in descending

 
0
  #3
Dec 1st, 2008
ok,
this is my modify code:
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 327
Reputation: quuba is on a distinguished road 
Solved Threads: 50
quuba quuba is offline Offline
Posting Whiz

Re: how to sort the output in descending

 
0
  #4
Dec 1st, 2008
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:
  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC