Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Making a string lowercase

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Making a string lowercase

    Hi I currently have to develop a application for my basic level java programming class, that takes a first, last and middle name entered. Then takes the first letter from first name, and middle name, and the first 4 letters of last name, and then adds a random generated number from 100-999 for a username.

    For example:

    If I entered: Raymond Jason Smith
    It would return: RJSmit222

    I need help on making all my generated username display in lowercase only, no matter if user enters it in uppercase


    import java.util.Random; 
    import java.util.Scanner;
     
     
     
        public class random {
     
        public static void main (String[] args) {
    	Scanner scan = new Scanner(System.in);
        Random random = new Random();
     
    	String first;
    	String middle;
    	String last;
     
    	    System.out.print ("First name? "); //prompts user for first name
    		first = scan.nextLine ();
    		System.out.print ("Middle name? "); //prompts user for middle name
    		middle = scan.nextLine ();
    	    System.out.print ("Last name? "); //prompts user for last name
    		last = scan.nextLine ();
     
    		System.out.println ("\nInputed first name was: " + first); //tells user inputed data - first name
    		System.out.println ("Inputed middle name was: " + middle);//tells user inputed data - middle name
    		System.out.println ("Inputed last name was: " + middle); //tells user inputed data - last name
     
    		int randomNumber = random.nextInt(899) + 100; //random generated number from 100-999 for username
    	    System.out.println ("Random computer generated number: " + randomNumber); //Tells user the generated number
     
    		System.out.print ("\nYour generated username is: " + first.charAt(0) 
    		                                  + middle.charAt(0) 
    									      + last.substring (0, 4) 
    										  + randomNumber); //echo generated username
     
     
        }
    }


  2. #2
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Making a string lowercase

    HI,

    U can use something like this

     System.out.print ("\nYour generated username is: " + first.toLowerCase().charAt(0)
                                              + middle.toLowerCase().charAt(0)
                                              + last.toLowerCase().substring (0, 4)
                                              + randomNumber); //echo generated username

  3. The Following User Says Thank You to mmrafi83 For This Useful Post:

    Raymond Pittman (February 14th, 2011)

  4. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Making a string lowercase

    Quote Originally Posted by mmrafi83 View Post
    U can use something like this
    Hooray spoonfeeding
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Making a string lowercase

    Hey I appreciate all the help guys.

Similar Threads

  1. making text editor using string class
    By petadeer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 14th, 2011, 03:28 AM
  2. Making a clock
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 7th, 2011, 04:36 PM
  3. about making .class into .jar
    By sibbe in forum Java Theory & Questions
    Replies: 7
    Last Post: November 13th, 2010, 01:50 PM
  4. ArrayList<String> convert to lowercase
    By s_mehdi76 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2010, 09:05 PM
  5. Digital map application with Java GUI
    By donjuan in forum AWT / Java Swing
    Replies: 3
    Last Post: May 15th, 2009, 03:32 AM