Results 1 to 20 of 20
- 10-28-2012, 07:07 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Problem with making the numbers display in ascending order?
Java Code:import java.util.Scanner; public class Order3 { public static void main (String[] args) { Scanner scan = new Scanner (System.in); System.out.println("Enter number 1"); int Number1 = scan.nextInt(); System.out.println("Enter number 2"); int Number2 = scan.nextInt(); System.out.println("Enter number 3"); int Number3 = scan.nextInt(); if(Number1 > Number2 && Number1 > Number3 && Number2 > Number3) { System.out.println(Number3 + " " + Number2 + " " + Number1); } if(Number2 > Number1 && Number2 > Number3 && Number1 > Number3){ System.out.println(Number2 + " " + Number1 + " " + Number3); } if(Number2 > Number1 && Number2 > Number3 && Number1 < Number3){ System.out.println(Number3 + " " + Number2 + " " + Number1); } if(Number3 > Number1 && Number3 > Number2 && Number2 > Number1){ System.out.println(Number2 + " " + Number3 + " " + Number1); } if(Number3 > Number1 && Number3 > Number2 && Number2 < Number1){ System.out.println(Number1 + " " + Number3 + " " + Number2); } } }Last edited by gardheere50; 10-29-2012 at 01:08 AM.
- 10-28-2012, 07:08 PM #2
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
Also I want to make this program except numbers that are the same like if the user writes "1 2 1 3" I want the program to display these numbers in order like "1123"..I hope thats makes sense...
- 10-28-2012, 08:08 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
Please guys help me..dont just view and move on to next post..
- 10-28-2012, 09:20 PM #4
Re: Problem with making the numbers display in ascending order?
1. Bumping a thread after just one hour is rude.
2. Please go through Guide For New Members and BB Code List - Java Programming Forum and edit your post accordingly.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-29-2012, 12:25 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
Followed the rules..sorry about that..now whats next and How can I get a solution to my problem..
- 10-29-2012, 12:28 AM #6
Re: Problem with making the numbers display in ascending order?
Ask a specific question. I have no idea where you are stuck. "I have no idea how to do this" is not specific and not a question.
- 10-29-2012, 12:35 AM #7
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
basically the program works, however rather than sorting the numbers the user inputted into an ascending order it sorts it in descending order, which where the problem lies. I want to the program to sort the numbers in ascending order...it doesn't do that and Also I want to make this program except numbers that are the same like if the user writes "1 2 1 3" I want the program to display these numbers in order like "1123"..I hope thats makes sense...
- 10-29-2012, 12:40 AM #8
Re: Problem with making the numbers display in ascending order?
So you code is working except you have the output in the wrong order.
In the above code it will print "20 10". If you want it to print "10 20" instead surely you can figure out what simple change needs to be made.Java Code:int num1 = 20; int num2 = 10; if(num1 > num2) { System.out.println(num1 + " " + num2); }
- 10-29-2012, 12:54 AM #9
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
thanks..but my is longer and hard to actually change to make it sort the numbers in ascending order.
- 10-29-2012, 12:56 AM #10
Re: Problem with making the numbers display in ascending order?
HTF is it harder to change?
This is what you currently have displaying the numbers in the wrong order. So simply swap Number1 and Number3.Java Code:System.out.println(Number1 + " " + Number2 + " " + Number3);
- 10-29-2012, 01:02 AM #11
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
but if I run the program after making the changes and I type in these numbers in this order "1, 3 , 2 " the program outputs " 2, 3 , 1..thats the confusing part for me..I have been trying to make it all day long...
- 10-29-2012, 01:07 AM #12
Re: Problem with making the numbers display in ascending order?
Then your conditions in the if statements are incorrect. Since you have not posted your updated code nobody can help you.
- 10-29-2012, 01:09 AM #13
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
sorry I have updated the code..
- 10-29-2012, 01:11 AM #14
Re: Problem with making the numbers display in ascending order?
Any chance you will show it to us? Or should we just guess?
- 10-29-2012, 01:22 AM #15
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
in line 20 I have changed the numbers around as you have suggested but still the code does not sort the numbers in ascending order
- 10-29-2012, 01:29 AM #16
Re: Problem with making the numbers display in ascending order?
Ffs, show your code!
- 10-29-2012, 01:32 AM #17
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
Java Code:if(Number2 > Number1 && Number2 > Number3 && Number1 > Number3){ System.out.println(Number2 + " " + Number1 + " " + Number3); }
- 10-29-2012, 01:43 AM #18
Re: Problem with making the numbers display in ascending order?
If your input is 1 3 2 then the if statement above will not be true as Number1 is not greater than Number3. So it must be entering a different if statement. One which you have not shown. You really do not want my help do you? Show your entire code!
- 10-29-2012, 01:45 AM #19
Member
- Join Date
- Oct 2012
- Posts
- 11
- Rep Power
- 0
Re: Problem with making the numbers display in ascending order?
Java Code:import java.util.Scanner; public class Order3 { public static void main (String[] args) { Scanner scan = new Scanner (System.in); System.out.println("Enter number 1"); int Number1 = scan.nextInt(); System.out.println("Enter number 2"); int Number2 = scan.nextInt(); System.out.println("Enter number 3"); int Number3 = scan.nextInt(); if(Number1 > Number2 && Number1 > Number3 && Number2 > Number3) { System.out.println(Number3 + " " + Number2 + " " + Number1); } if(Number2 > Number1 && Number2 > Number3 && Number1 > Number3){ System.out.println(Number2 + " " + Number1 + " " + Number3); } if(Number2 > Number1 && Number2 > Number3 && Number1 < Number3){ System.out.println(Number3 + " " + Number2 + " " + Number1); } if(Number3 > Number1 && Number3 > Number2 && Number2 > Number1){ System.out.println(Number2 + " " + Number3 + " " + Number1); } if(Number3 > Number1 && Number3 > Number2 && Number2 < Number1){ System.out.println(Number1 + " " + Number3 + " " + Number2); } } }
- 10-29-2012, 01:51 AM #20
Re: Problem with making the numbers display in ascending order?
No pretend you are the computer. Which of those if statements will be true if the input is 1 3 2?
1 is not greater than 3 so the first one is false.
Keep going for all of them and test it for yourself. One problem is for 3 numbers there are 6 possible combinations and yet you only have 5 if/print statements.
Similar Threads
-
search array - ascending order
By wiola111 in forum New To JavaReplies: 5Last Post: 08-28-2012, 03:09 PM -
Sorting in ascending and descending order
By flpanthers1 in forum New To JavaReplies: 10Last Post: 06-27-2011, 03:48 PM -
ascending order using array rush
By jca in forum New To JavaReplies: 2Last Post: 01-03-2011, 04:24 AM -
Checking ascending order of array
By counterfox in forum New To JavaReplies: 3Last Post: 10-22-2010, 10:44 PM -
How to add coins in ascending order in arraylist
By tribujohn in forum New To JavaReplies: 2Last Post: 01-23-2009, 04:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks