java - Capitalize First Letter of Last Name -
java - Capitalize First Letter of Last Name -
i want lastly name print there first letter capitalized of lastly name capitalized. want user input name hashemite kingdom of jordan torres , give torres, j.
import java.util.*; // scanner public class processname { public static void main(string[] args) { string name; scanner console = new scanner(system.in); system.out.print("type name: "); //send user name = console.nextline(); string[] namearray = name.split(" ");//split string array string firstname = name.valueof(name.charat(0)).touppercase(); //get first letter string lastname = name.substring(name.indexof(" ") + 1).touppercase(); string myname = lastname + ", " + firstname;//give lastly , first name system.out.println("your name is: " + myname + ".");
my output torres, j.
// lastly name entered user string lastname = name.substring(name.indexof(" ") + 1); // upcase first character, append remaining characters lastname = character.touppercase(lastname.charat(0)) + lastname.substring(1);
java capitalization
Comments
Post a Comment