For an assignment ive had to have a problem read in a string and then display the string and state if the letters in the string are ascending or not. I've managed to do this however i swear no matter where i add either
if ( input.equals( "END" ){
break;
}
or a
while ( ! input.equals( "END" ){
break;
}
it won't break after i receive "letters are not in ascending order"
Heres the code with the simplistic ifs
class Main { public static void main( String args[] ) { System.out.print("#Enter Word Here:"); String input = BIO.getString(); char[] characters = input.toCharArray(); boolean haveSwapped = true; while ( haveSwapped ) { if ( input.equals( "END") ){ break; } haveSwapped = false; for (int i=0; i<characters.length-1; i++) { if ( characters[i] > characters[i+1] ) { char tmp = characters[i]; characters[i] = characters[i+1]; characters[i+1] = tmp; haveSwapped = true; System.out.print( input ); System.out.println(" letters are not in ascending order"); System.out.print("#Enter Word Here:"); input = BIO.getString(); if ( input.equals( "END") ){ break; } characters = input.toCharArray(); i = 0; } } System.out.print( input ); System.out.println(" letters are in ascending order"); System.out.print("#Enter Word Here:"); input = BIO.getString(); characters = input.toCharArray(); haveSwapped = true; if ( input.equals( "END") ){ break; } } } }
Is it possible? where and how? :S thanks for any help.