Results 1 to 9 of 9
  1. #1
    mistah is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default Monogram program

    Its supposed to ask for a first name, middle initial, and a last name

    the output should say the initials of each, with the middle initial as capital

    it should be looking somthing like

    Enter your first name: Michal
    Enter your middle initial: K
    Enter your last name: Lastname

    Your monogram is: mKl


    this is what I am having so far

    Java Code:
    import java.util.Scanner;
    
    public class Ch6Ex18 {
      public static void main (String[]args) {
        //declare vars
        String first, middle, last, monogram;
        Scanner input = new Scanner (System.in);
        
        System.out.println("Enter your first name: ");
        first = input.nextLine();
        System.out.println("Enter your middle initial: ");
        middle = input.nextLine();
        System.out.println("Enter your last name: ");
        last = input.nextLine();
        input.close();
        
        monogram =
        
          
      }
    }
    please help!! :D

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Good start...

    OK, to go further you need to use the methods String class has. Here's a link to the Java API for the String class:
    String (Java Platform SE 6)
    The method that you would probably be using is charAt().
    Here's a tutorial about strings and the things you can do with them:
    Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Belbis's Avatar
    Belbis is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    good links to use..also google searches can help if you have specific problems.
    Last edited by Belbis; 12-22-2008 at 11:19 PM.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default See my post

    Belbis: please see my response to Mohamed about posting complete code:
    My program is not working
    Posting complete code in these cases is probably not the best solution and doesn't help the OP.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    Belbis's Avatar
    Belbis is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    noted CJSL, I see your point

    -Belbis

  6. #6
    mohamed gaber is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Smile your solution

    hi
    i reviced your code and post the solution for u
    import java.util.Scanner;

    public class Ch6Ex18 {
    public static void main (String[]args) {
    //declare vars
    String first, middle, last, monogram;
    Scanner input = new Scanner (System.in);

    System.out.println("Enter your first name: ");
    first = input.nextLine();
    System.out.println("Enter your middle initial: ");
    middle = input.nextLine();
    System.out.println("Enter your last name: ");
    last = input.nextLine();
    input.close();

    monogram =String.valueOf(first.charAt(0)).toLowerCase()+Str ing.valueOf(middle.charAt(0)).toUpperCase()+String .valueOf(last.charAt(0)).toLowerCase();
    System.out.println(monogram);


    }
    }

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Why?

    Mohamed... why do you insist on posting complete code solutions. I've already explained to you why you shouldn't do this. You are not helping the OP.
    If you want to help, then explain to the OP, step by step, what that last part of your program does.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    My guess: It's because Mohamed's too lazy to explain. It's much easier just spitting out the code.

  9. #9
    mistah is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default

    thank you very much, i appreciate all the help!
    i asked my teacher about this and he explained it to me
    ..but i appreciate the help!
    especially cjsl and mohamed _gaber:)

Similar Threads

  1. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •