letters are in ascending order or not in ascending order.

• 11-21-2012, 06:30 PM
hawkesey
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
• 11-21-2012, 06:54 PM
KevinWorkman
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?
• 11-22-2012, 12:14 AM
hawkesey
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by KevinWorkman
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.
• 11-22-2012, 01:23 AM
Junky
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by hawkesey
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.
• 11-22-2012, 04:49 PM
hawkesey
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by Junky
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.
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";                       }                    }             }     }   }```
• 11-23-2012, 04:04 AM
Junky
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by hawkesey
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?
• 11-23-2012, 03:52 PM
hawkesey
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by Junky
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.
• 11-23-2012, 05:21 PM
DarrylBurke
Re: letters are in ascending order or not in ascending order.
Quote:

Originally Posted by hawkesey
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
• 11-23-2012, 05:39 PM
hawkesey
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