nextLine problems, any help appreciated
so far for my program i have
Code :
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
Re: nextLine problems, any help appreciated
mmm... extracting first and last names from a string. It looks like you were able to extract the first letter of the first name. Now, I'm assuming that the last name is only one word, and is separated from the first name by a space. Then, to find the last name we just need the last space character, and take everything after it as the last name.
Ex:
Code :
John Elwood Smith
^
Last space character is here, everything after is the last name
There are numerous ways to do this, but the easiest is to look at every character starting from the back of the string until you've found a space, then that's the last space character.
Re: nextLine problems, any help appreciated
This is what i thought. i cant seem to remember how to do this, if you could explain a bit more, thnx much