Hi all so I'm very new to Java and am working on a project which requires my program works properly with all name inputs, but I coded it to only output what I need with one.
What I did was initialize my fullname into first and lastname using substrings, but that obviously won't work for any name because there will be a different number of characters.
Here's the code :
public class Proj2 { public static void main(String[] args) { String fullname = "dAvId lAwReNt"; String firstname; String lastname; firstname = fullname.substring(0,5); lastname = fullname.substring(6,13); int count = fullname.length(); System.out.println("Index of Space:" + fullname.length()); System.out.println("First Name: " + firstname + " has " + firstname.length() + " letters."); System.out.println("Last Name: " + lastname + " has " + lastname.length() + " letters."); firstname = firstname.toUpperCase(); lastname = lastname.toUpperCase(); System.out.println("Initial of the first name in uppercase: " + firstname.charAt(0)); firstname = firstname.toLowerCase(); System.out.println("Rest of the first name in lowercase: " + firstname.substring(1)); System.out.println("Initial of the last name in uppercase: " + lastname.charAt(0)); lastname = lastname.toLowerCase(); System.out.println("Rest of the last name in lowercase: " + lastname.substring(1)); firstname = firstname.toLowerCase(); lastname = lastname.toLowerCase(); firstname = firstname.substring(0, 1).toUpperCase() + firstname.substring(1); lastname = lastname.substring(0, 1).toUpperCase() + lastname.substring(1); System.out.println("My name is " + firstname + " " + lastname); } }
I just need to set firstname and lastname without using substrings since that won't work if i were to replace the name with another with a different amount of characters