Tuesday, June 21, 2011

First Letter Capitalization In Java

Hey! It's 11:11pm.
Make a wish! :D

Alright, 11:11pm over. Haha.
Now, a very good evening to everyone. I had just finished helping Jez code a Java program. Good gosh, I feel so accomplished. Haha.

import java.util.Scanner;
public class FirstLastName2 
{
public static void main (String[] args)
{
String firstName;
String lastName;
String lastNameCap;
String firstNameCap;

String firstLetterFirst;
String remainderFirst;
String firstLetterLast;
String remainderLast;

Scanner keyBoard = new Scanner(System.in);


System.out.print("Enter your first name: ");
firstName = keyBoard.nextLine();
System.out.print("Enter your last name: ");
lastName = keyBoard.nextLine();

firstLetterFirst = firstName.substring(0,1);  // Get first letter
  remainderFirst   = firstName.substring(1);    // Get remainder of word
  firstNameCap = firstLetterFirst.toUpperCase() + remainderFirst.toLowerCase();


firstLetterLast = lastName.substring(0,1);  // Get first letter
  remainderLast   = lastName.substring(1);    // Get remainder of word
  lastNameCap = firstLetterLast.toUpperCase() + remainderLast.toLowerCase();

System.out.print("Your fullname is: " + firstNameCap + " " + lastNameCap);
}
}

Yeah, I suppose that doesn't make sense to many of you.
That whole gunk of codes up there basically just asks you for your first name and last name and then displays your full name with the first letters of your first name and last name capitalized.
The program looks somewhat like this.

Enter your first name: joanna
Enter your last name: morales
Your full name is: Joanna Morales

So... yeah. That's what it does.
Yadayadaflipflop, boring things. Haha.

I got home from PE some two hours ago. We had volleyball drills and stuff.  It's unbelievable how tired all that physical activity left me. It actually wasn't as strenuous as I tried to make it seem but, darn it, am I exhausted.
LOL. I'M SO UNHEALTHY.

Discrete Mathematics and Physics; I've yet to do my assignments for them.
I should have gotten them done sooner.
Oh, fudgeballs.

Sleep sounds really good right now.

No comments:

Post a Comment