Results 1 to 5 of 5
  1. #1
    Thammer is offline Member
    Join Date
    Sep 2014
    Posts
    47
    Rep Power
    0

    Default How to ignore lowercase and upercase letters.

    Hi,

    I have made a program, where the user types in a letter M, C or I to identify their major, if the user types m, c or i, my code does not work.
    How could I make my program ignore if the letter is upercase or lowercase? My code is posted below.
    Can I do this in any easier way then adding this type of code for each lowercase letter?:
    Java Code:
     if (s.charAt(0) == 'm')
    System.out.print("Mathematics ");
    My current code:
    Java Code:
    import java.util.Scanner;
    
    public class c4e18 {
    	public static void main(String[]args){
    		Scanner input = new Scanner(System.in);
    	    System.out.print("Enter two characters: ");
    	    String s = input.nextLine();
    	    
    	    if (s.charAt(0) == 'M')
    	      System.out.print("Mathematics ");
    	    else if (s.charAt(0) == 'C')
    	      System.out.print("Computer Science ");
    	    else if (s.charAt(0) == 'I')
    	      System.out.print("Information Technology ");
    	    else 
    	    {
    	      System.out.println("Input major code");
    	      System.exit(1);
    	    }
    
    	    if (s.charAt(1) == '1')
    	      System.out.println("Freshman");
    	    else if (s.charAt(1) == '2')
    	      System.out.println("Sophomore");
    	    else if (s.charAt(1) == '3')
    	      System.out.println("Junior");
    	    else if (s.charAt(1) == '4')
    	      System.out.println("Senior");
    	    else 
    	    {
    	      System.out.println("Input status code");
    	      System.exit(2);
    	    }
    	}
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to ignore lowercase and upercase letters.

    Yep! There's a way. But I am going to make you look at the String API in the JDK to figure it out. But there are
    two methods you could use depending on whether you are using strings or characters. You need to bookmark
    Java Platform SE 8 in your browser. I use it all the time because I can't remember
    all the methods (like I just did with the String class).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Thammer is offline Member
    Join Date
    Sep 2014
    Posts
    47
    Rep Power
    0

    Default Re: How to ignore lowercase and upercase letters.

    Quote Originally Posted by jim829 View Post
    Yep! There's a way. But I am going to make you look at the String API in the JDK to figure it out. But there are
    two methods you could use depending on whether you are using strings or characters. You need to bookmark
    Java Platform SE 8 in your browser. I use it all the time because I can't remember
    all the methods (like I just did with the String class).

    Regards,
    Jim
    Thanks Jim, I have a look at it tomorrow and see if I figure it out :)
    Getting late here in Norway!

  4. #4
    ykms is offline Member
    Join Date
    Oct 2014
    Posts
    1
    Rep Power
    0

    Default Re: How to ignore lowercase and upercase letters.

    you can add ths

    Character.toLowerCase(name1.charAt(i))==Character .toLowerCase('m')

    or

    Character.isUpperCase('M')

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    9

    Default Re: How to ignore lowercase and upercase letters.

    @ykms Did the OP not say they were going to try and figure this out? Additionally, why are you converting the lower case 'm' to lower case?

    Regards.

Similar Threads

  1. Textfield lowercase and uppercase
    By rdbll in forum New To Java
    Replies: 2
    Last Post: 02-19-2014, 11:25 AM
  2. How to lowercase all arguments
    By reverton in forum New To Java
    Replies: 1
    Last Post: 04-28-2013, 06:35 AM
  3. Convert English letters to Tamil letters
    By srinivasmallabathula in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 02:39 PM
  4. Random lowercase letter
    By codeAJ in forum New To Java
    Replies: 3
    Last Post: 05-31-2011, 01:54 AM
  5. uppercase and lowercase please help
    By cuziwow in forum New To Java
    Replies: 4
    Last Post: 04-11-2010, 07:54 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
  •