Results 1 to 9 of 9
  1. #1
    hawkesey is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default letters are in ascending order or not in ascending order.

    Hello

    I am currently learning about OO programming with java i am starting to get the grasp of it to some extent and i am finding it enjoyable.

    One of the exercises i have been set by my lecturer, here is the brief:-

    Read in a word and display if the letters are in ascending order or not in ascending order. Ignore letter case in your comparison.

    I have an idea how to achieve this it is just implementing it that im not sure about.

    Any help would be appreciated

    Thanks

    Josh

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: letters are in ascending order or not in ascending order.

    What have you tried? Where are you stuck? Which part of this is giving you trouble?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    hawkesey is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by KevinWorkman View Post
    What have you tried? Where are you stuck? Which part of this is giving you trouble?

    Well i have had the thought that i need to get the program to look at each letter in the string and compare it to the lasst to see see if it is >= to the last. and if this is true for all of the letters then it will return true and false if not. Here is what i have done so far it is just my thoughts really i have not yet come across away to implement how i think the problem should be solved.

    public class Main
    {
    public static void main (String args[])

    {

    System.out.print("#Enter phrase\n");
    String P=BIO.getString();


    while (! P.equals("END"))
    {
    /**
    if (R.equals("TRUE"))
    {
    System.out.printf("%s letters in ascending order\n",P);
    }

    else if (R.equals("FALSE"))
    {
    System.out.printf("%s letters not in ascending order\n",P);
    }
    **/

    System.out.print("#Enter phrase\n");
    P=BIO.getString();

    for (int x=0; x<P.length; x=x+1)
    {
    }
    }
    }
    }



    Thanks

    also is there an area of this site where i can upload code and get some feedback on it.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by hawkesey View Post
    Well i have had the thought that i need to get the program to look at each letter in the string and compare it to the lasst to see see if it is >= to the last.
    Yep, that would be the best way. The String class has a method to extract a single letter. It also has methods to change the case (upper-lower, lower-upper) to handle the ignore case requirement.

  5. #5
    hawkesey is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by Junky View Post
    Yep, that would be the best way. The String class has a method to extract a single letter. It also has methods to change the case (upper-lower, lower-upper) to handle the ignore case requirement.
    i have this so far it is an adaptation to a program that i wrote to count vowels in a phrase.
    Java Code:
    public class Main
     {   
        public static void main (String args[])
            
         {  
               String R="a";
              
               System.out.print("#Enter phrase\n");
               String P=BIO.getString();
               
                
               while (! P.equals("END"))
                {
                   
                   if (R.equals("TRUE"))
                    {
                       System.out.printf("%s letters in ascending order\n",P);
                    }
                        
                   else if (R.equals("FALSE"))
                    {
                       System.out.printf("%s letters not in ascending order\n",P);
                    } 
                    
                   System.out.print("#Enter phrase\n");
                   P=BIO.getString(); 
                
                   for (int x=0; x<P.length(); x=x+1) 
                      {
                         if (P.charAt(x)>=x)
                          { 
                             R="TRUE";
                          }  
                         else if (P.charAt(x)<x)
                          {
                              R="FALSE";
                           }   
                      } 
                }
        }
      }

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by hawkesey View Post
    i have this so far
    Good for you. Do you have a question? I have one. Why are you using "TRUE" and "FALSE" as Strings instead of booleans?

  7. #7
    hawkesey is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by Junky View Post
    Good for you. Do you have a question? I have one. Why are you using "TRUE" and "FALSE" as Strings instead of booleans?
    Can i just say that there is absolutely no need for rudeness. As i said i am not that competent with java yet.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: letters are in ascending order or not in ascending order.

    Quote Originally Posted by hawkesey View Post
    Can i just say that there is absolutely no need for rudeness. As i said i am not that competent with java yet.
    I don't see any rudeness there, just a word of encouragement and two questions you need to answer to get better help here.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    hawkesey is offline Member
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: letters are in ascending order or not in ascending order.

    it just appeared to be written in a way that sounds rude. sorry if there is a misunderstanding

Similar Threads

  1. search array - ascending order
    By wiola111 in forum New To Java
    Replies: 5
    Last Post: 08-28-2012, 03:09 PM
  2. Sorting in ascending and descending order
    By flpanthers1 in forum New To Java
    Replies: 10
    Last Post: 06-27-2011, 03:48 PM
  3. ascending order using array rush
    By jca in forum New To Java
    Replies: 2
    Last Post: 01-03-2011, 04:24 AM
  4. Checking ascending order of array
    By counterfox in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 10:44 PM
  5. How to add coins in ascending order in arraylist
    By tribujohn in forum New To Java
    Replies: 2
    Last Post: 01-23-2009, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •