Separate combined words in a sentence and convert them into Pig Latin My program is complete and working, but I would like second opinions on it.

Here are the instructions for the assignment:


  
  The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase.
  Convert the string to a string in which the words are separated by
  spaces and only the first word starts with an uppercase letter. For
  example, the string "StopAndSmellTheRoses" would be converted to "Stop
  and smell the roses".
  Then the program will convert each word in the result string of task 1 into "Pig Latin". In one version of Pig Latin, you convert a
  word by removing the first letter, placing that letter at the end of
  the word, and then appending "ay" to the word.
  
  
  For example, for the result string "Stop and smell the roses" in task
  1, the Pig Latin string should be "topSay ndaay mellsay hetay osesray".
  
  Requirements:
  
  
  Your program should have 3 methods: a main method, a method for task    1, and a method for task2.
  The method for task 1 should return the result string of task1.
  The method for task 2 should display the Pig Latin string.
  




import java.util.Scanner; 
public class Assignment9
{
    public static void main(String[] args) 
    {   
    // Variables
    String sentence, revisedSentence, latin = " "; 

    // Create a Scanner object for keyboard input
    Scanner keyboard = new Scanner(System.in); 

    // Get the input string
    System.out.print("Enter sentence: ");
    sentence = keyboard.nextLine(); 

    //Close keyboard
    keyboard.close();

    // Task 1 
    revisedSentence = WordSeparator(sentence); 

    System.out.print("Revised Sentence: " +revisedSentence); 

    // Task 2
    PigLatin(revisedSentence, latin); 

    System.exit(0); 
}

private static String WordSeparator(String sentence) 
{
    // Variables 
    StringBuilder str = new StringBuilder(sentence); 
    int i = 1; 

    // While loop repeats until the end of the sentence
    while (i &lt; str.length())
    {
        // Checks for upper case characters
        if(Character.isUpperCase(str.charAt(i)))
        {
            //Inserting space
            str.insert(i, ' '); 
            char ch = Character.toLowerCase(str.charAt(i+1)); 
            str.setCharAt((i+1), ch); 
        }
        i++; 
    }
    return str.toString();
}

private static void PigLatin(String revisedSentence, String latin) 
{   
    // Split sentence by spaces
    String[] tokens = revisedSentence.split(" ");

    // Store all the words into an array
    String[] arr = new String[tokens.length];       

    // Convert English sentence into Pig Latin 
    for (int i = 0; i &lt; tokens.length; i++)
    {
        // Get string from array
        String str = tokens[i]; 

        // Get first letter from string
        String str1 = str.substring(0, 1); 

        // Get substring from string
        String str2 = str.substring(1, str.length()); 

        // Concatenate the two strings in a required format
        str2 = str2.concat(str1); 

        // Concatenate the result and "AY" 
        str2 = str2.concat("ay"); 

        // Store all of the strings into an array
        arr[i] = str2; 

        // Make a sentence with all the words 
        latin = latin.concat(str2 + " "); 
    }

    // Display pig latin verison
    System.out.println("\nPig Latin Version:" +latin ); 
    }

}
This is in addition to what @thecoder16 already said.

WordSeparator

Methods should be named using verbs instead of nouns.
They usually take some action on the input,
for example this method separates the words that were stuck together.
So separateWords would be better.

Also, this part is not great:


    // Checks for upper case characters
    if(Character.isUpperCase(str.charAt(i)))
    {
        //Inserting space
        str.insert(i, ' '); 
        char ch = Character.toLowerCase(str.charAt(i+1)); 
        str.setCharAt((i+1), ch); 
    }



Objections:


The str.charAt(i) and str.charAt(i+1) refer to the same character. This is repetitive, and can be prone to errors, as you have to remember to use i+1 the second time because of the inserted space
The comments only state the obvious. Unnecessary comments are like noise, and a waste of time to read. Let the code speak for itself.


It would be better this way:

    char ch = str.charAt(i);
    if (Character.isUpperCase(ch)) {
        str.insert(i, ' ');
        str.setCharAt(i + 1, Character.toLowerCase(ch));
    }


PigLatin

The biggest issue here is the latin = latin.concat(...) call for two reasons:


String concatenation is inefficient. You should use a StringBuilder like you did in your other method.
Reusing input parameters is not a good practice, as it can be confusing and error prone. It would be better to name local variables differently.


Issues similar to WordSeparator:


The method is poorly named. Perhaps toPigLatin would be better.
The comments are unnecessary noise


Other smaller issues:


Instead of printing output, it would be better to return the result
The String[] arr is unused, so it would be better to remove it
The counting for loop can be converted to an enhanced loop, for example: for (String str : tokens) { ... }
The input parameter revisedSentence carries information that's unnecessary for the functioning of this method. Just sentence would be enough.