Showing posts with label capital first letter in java. Show all posts
Showing posts with label capital first letter in java. Show all posts

Wednesday, August 5, 2015

First Letter Capital Program in Java

As I continue my study on Java I have discovered that Java programming language has many built in functions that makes programming much easier and more fun specially we are working with strings. I enjoy every minute working with Java. No wonder there are many programmers, developers and software engineers find it very useful in many programming project because it is a very versatile programming language.

In this article I would like to share with you guys a sample program that I wrote in Java that will ask the user to give a sentence and then our  program will convert the first letter of the sentence into uppercase letter. I have created a method on it that well convert the first letter of the word in a give sentence by our user.  In addition our program it will ask the user if the user would want to repeat the program running by asking the user do you want to continue yes or not.
 
If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.
 
 
 
 
Sample Program Output 
 
 
Program Listing
 
 
// find_upper_case.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : August 5, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
// Write a program that will conver the first letter of a word into capital
// letters


 import java.util.Scanner; 
  
 public class find_upper_case { 
  
public static String Upper_First_Letter(String str)
{
    boolean check_space = true;
    char[] chars = str.toCharArray();
    for (int a = 0; a < chars.length; a++) {
        if (Character.isLetter(chars[a])) {
            if (check_space) {
                chars[a] = Character.toUpperCase(chars[a]);   
            }
            check_space = false;
        } else {
            check_space = Character.isWhitespace(chars[a]);
        }
    }
    return new String(chars);
}
 
    public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
     char ch;
                  
  do {
     String sentence,repeat;
     repeat = input.nextLine();
     System.out.print("FIRT LETTER CAPITAL PROGRAM");
     System.out.println();   
     System.out.print("Enter a Sentence : ");
     sentence = input.nextLine();
     System.out.println();
     System.out.println("ORIGINAL SENTENCE");
     System.out.print(sentence);
     System.out.println("\n\n");
     System.out.println("CONVERTED SENTENCE");
     System.out.print(Upper_First_Letter(sentence));
     System.out.println();
      System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                       
     } while (ch == 'Y'|| ch == 'y'); 
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println();
    }
}