Results 1 to 8 of 8
- 01-14-2013, 04:52 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
ascending order or not in ascending order
Hello
I am fairly new to java and i am currently one of the modules that i am studding at university. I need to create a program that will read in a string and then work out if it is in ascending order or not in ascending order and return true or false.
Below is the brief

Thanks and any help will be much appreciated
- 01-14-2013, 04:59 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: ascending order or not in ascending order
And....What have you tried?
- 01-15-2013, 11:46 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
Re: ascending order or not in ascending order
- 01-15-2013, 12:01 PM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: ascending order or not in ascending order
Yes you need probably to use arrays - you won't get more until you actually present your code, so we can see what you actually did and where you are having problems. Then people will help you out! Looking at things will not write your assignment...
I like likes!.gif)
- 01-15-2013, 12:38 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: ascending order or not in ascending order
You don't need arrays; all you need is a boolean expression for a String s: s.charAt(i) <= s.charAt(i+1) that needs to be true for all applicable values of i to be in ascending order.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-16-2013, 11:33 AM #6
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
- 01-16-2013, 12:13 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 9
- Rep Power
- 0
Re: ascending order or not in ascending order
This is what i have done so far it is has been done quick to get some of my thoughts down.Java Code:public class Main { public static void Main (String args[]) { System.out.println("Enter phrase"); String p = BIO.getString(); while (! p.equals("END")) { boolean inorder = true; while ( inorder ) { inorder=false; for (int i=0; i<p.length(); i=i+1) { if ((p.charAt(i) <= p.charAt(i+1))) { inorder = true; } } if (inorder=true) { System.out.printf("%s letters in ascending order,p"); } System.out.println("Enter phrase"); p = BIO.getString(); } } } }
THanks
- 01-16-2013, 12:56 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: ascending order or not in ascending order
There are at least three mistakes in that code:
1) check the terminating condition of that for-loop;
2) if that expression happens to be true once, the characters don't need all to be in ascending order;
3) check that assignment in line #32.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
letters are in ascending order or not in ascending order.
By hawkesey in forum New To JavaReplies: 8Last Post: 11-23-2012, 04:39 PM -
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 -
How to add coins in ascending order in arraylist
By tribujohn in forum New To JavaReplies: 2Last Post: 01-23-2009, 04:31 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks