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 2 of 2

Thread: any help is much appreciated

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default any help is much appreciated

    so far for my program i have
    import java.util.*;
     
    public class CalculateChange
    {
         public static void main(String[] args)
         {
              String s1, s2;
              Scanner keyboard = new Scanner(System.in);
     
              System.out.print("Enter your name: ");
              s1 = keyboard.nextLine();
     
              System.out.print("Enter current date: "); // in format of mm/dd/yyyy
              s2 = keyboard.nextLine();
     
              String mutation1, mutation2, mutation3;
              mutation1 = s1;
              mutation2 = mutation1.toUpperCase();
              mutation3 = mutation2.substring(0, 1);
     
              System.out.println("===== Ref. # " + mutation3);
         }
    }

    i am stuck from here... for the last line it is to print in the format
    of ===== Ref. #JSMITH091003 =====
    Where the J is the first letter of the name entered for s1 and SMITH is the last
    name entered for s1 and then 091003 for the date in format of yy/mm/dd
    Note that JSMITH is not what hte user entered just an example of the output and i cant use the Next( ) method
    Last edited by helloworld922; October 8th, 2009 at 07:47 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: any help is much appreciated

    I'm assuming here that the the string contains only the first and last name, and that they are separated by a single space:

    public static String getNameString(String fullName)
    {
         // find the last space
         for (int i = fullName.length() - 1; i>=0; i--)
         {
              if (fullName.charAt(i) == ' ')
              {
                   return fullName.charAt(0) + fullName.substring(i+1,fullName.length());
              }
         }
         throw new RuntimeException("Error! Could not find a space");
    }

Similar Threads

  1. nextLine problems, any help appreciated
    By Schmitz14 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 5th, 2009, 01:23 AM
  2. Need a little help. would be greatly appreciated
    By ryan29121 in forum Java Theory & Questions
    Replies: 4
    Last Post: September 27th, 2009, 02:03 PM