Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Here is a Working Code. ^_^
    Java Code:
    import java.util.Scanner;
    
    public class MrInitials {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            String result;
            System.out.print(" enter your first name ");
            String first = scanner.nextLine();
            System.out.print(" enter your last name ");
            String last = scanner.nextLine();
                    
                    if(first.substring(0,1).equalsIgnoreCase(last.substring(0,1)))
                            {result = "Your name is " + first.toUpperCase() + " " 
                                     + last.toUpperCase();}
    			else
    			{result = "Your name is " + first.toLowerCase() + " " 
                                     + last.toLowerCase();}
                    System.out.println(result);
        }
    }
    Here is a Sample Output:
    Java Code:
     enter your first name 
    Adam
     enter your last name 
    Apple
    Your name is ADAM APPLE

    Java Code:
     enter your first name 
    Eve
     enter your last name 
    Apple
    Your name is eve apple
    I hope this helps. =P
    Last edited by Eku; 05-30-2008 at 07:58 AM.
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  2. #22
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #23
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    ^_^ using String.substring(0) is also String itself.

    I got that same problem during my training days. The tutorial in java is sometimes confusing at first so it wouldnt hurt to ask. =P I hope you got the error.

    Note in using toUpperCase and toLowerCase. in your code you use first.toUpperCase(); but you didnt store the result in any variable.
    you can use "first = first.toUpperCase();" or like the example above i directly stored it into the result string. You can read more on String Manipulations in Java tutorial. =)

    Or you can use a more simplier approach.
    Java Code:
    if(first.charAt(0)==last.charAt(0))
    But this is more of a Case Sensitive If. ^_^
    Last edited by Eku; 05-30-2008 at 08:15 AM.
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  4. #24
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Java tutorials have best explanation on anything. But the practice make complete. I found that most of our members here in our community, just waiting for someone's code. Even they found clues from members don't try at all.

    But not all members, just few. ;) Better to keep in my mind, just a few.

  5. #25
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    i got your point Erranga. ^_^ I have seen some in other forums, they asking for the code without even trying. They even put up a figth with the seniors and moderators when they are already giving the hints and samples. =)
    Im happy its not happening here. Moderators and Senior Members are friendly and has a Long Temper. ^_^

    Anyways i think my reply is quite late. I have been sick for 3 days. If Zebra has more questions just post it here we'll reply as soon as we can. Else, mark the thread [SOLVED] ^_^
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  6. #26
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Page 2 of 2 FirstFirst 12

Similar Threads

  1. urgent:calling c program from java
    By rach in forum New To Java
    Replies: 6
    Last Post: 01-19-2010, 11:37 AM
  2. Noob question- easy
    By mattonitto in forum New To Java
    Replies: 7
    Last Post: 06-13-2008, 12:26 AM
  3. What does this mean (Very Easy)
    By Zebra in forum New To Java
    Replies: 6
    Last Post: 05-01-2008, 01:46 PM
  4. help me with a realy easy program (substring)
    By michcio in forum New To Java
    Replies: 7
    Last Post: 01-27-2008, 12:41 AM
  5. Easy question
    By JavaNoob in forum New To Java
    Replies: 10
    Last Post: 08-03-2007, 10:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •