Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab9;
- import java.util.Scanner;
- /**
- *
- * @author Hieu
- */
- public class Lab9 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- String input;
- System.out.print("Enter a string: ");
- input = keyboard.nextLine();
- System.out.print(getString(input));
- }
- public static String getString(String inputString){
- String result ="";
- if (inputString.length()==0){
- return result;
- }
- char firstChar=inputString.charAt(0);
- char firstCharToUpperCase=Character.toUpperCase(firstChar);
- result= result+firstCharToUpperCase;
- for(int i=1; 1<inputString.length();i++){
- char currentChar = inputString.charAt(i);
- char previousChar = inputString.charAt(i - 1);
- if (previousChar == ' ') {
- char currentCharToUpperCase = Character.toUpperCase(currentChar);
- result = result + currentCharToUpperCase;
- }
- else {
- char currentCharToLowerCase = Character.toLowerCase(currentChar);
- result = result + currentCharToLowerCase;
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement