Upper & lower (mixed) case String display according to grammar


Explanation: 
           You enter text in upper and lower mixed case the programs automatically and intelligently arrange all the letter according to grammar rules. The first letter of the name will be display in upper case and rest of the letter are in lower case even you enter all the letters in upper case. Have a look on the code

Source code:

import java.util.Scanner;

class JavaPractice {
       
        public static void main(String[] args) {
                System.out.println("\t\tInput validation for string\n\n\n");
                // of getting input
                Scanner scan = new Scanner (System.in);
                // declare a variable for storing the name
                String name;
                //message for user
                System.out.print("Please enter your name (without space):");
                name=scan.next();
                // for get the length of name
                int lengthOfname=name.length();
               
                System.out.println("Welcome Mr."+name.substring(0, 1).toUpperCase()+name.substring(1,lengthOfname).toLowerCase());
       
      }
}

Comments

Popular posts from this blog

Operating System | Best Definition of Opetating System

Umbrella activities in Software Engineering