Wednesday, 15 July 2015

Java Programs Made Easy

Q)...Enter yout name and return a string "print the title first and then comma and then first letter of initial name.



  1. package Set1;
  2. import java.util.*;
  3. public class ClassSet31 {
  4.  public static String retrieveName(String s1){
  5.   StringTokenizer t=new StringTokenizer(s1," ");
  6.   String s2=t.nextToken();
  7.   String s3=t.nextToken();
  8.   StringBuffer sb=new StringBuffer(s2);
  9.   sb.append(',').append(s3.charAt(0));
  10.   return sb.toString();
  11.  }
  12.  public static void main(String[] args) {
  13.   String s1="Bhavane Raghupathi";
  14.   System.out.println(retrieveName(s1));
  15.  }
  16. }