Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming gpu hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Java sorting help

Reply  
Thread Tools
wateva's Avatar
Senior Member with 781 posts.
 
Join Date: Apr 2006
Location: Canada
23-Sep-2006, 09:04 PM #1
Java sorting help
So I'm using bubble sort to basically take a string and return it in ascending order of alphabets. It works fine as long as there is not a capital character but if there is a capital character it is automatically placed at the begining. Is there a function I could used to get to ignore capital characters? In case of string I know there is a ignoreCase function but I'm converting the original string to a char array before sorting it, so what do I do in case of chars?

Code:
public class Main {
    public static void main(String[] args){
        String a = "aome text";
        char[] string = a.toCharArray(); 
        int i;
        int j;
        char temp;
        for(i = 0; i < string.length - 1; i++){
            for(j = 0; j < string.length - 1; j++){
                if (string[j + 1] < string[j]){
                    temp = string[j + 1];
                    string[j + 1] = string[j];
                    string[j] = temp;
                }//end if statement
            }//end inner loop
        }// end outer loop
        
       String output = new String(string);
       output = output.trim(); 
       System.out.print(output);
       
    }//end function
    
}// end class
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
23-Sep-2006, 09:52 PM #2
Use toLowerCase() to change the case of the characters.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:47 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.