Write a java program to modify a string.

Write a program to input a person’s name in the format “FirstName LastName” and return the person name in the following format – “LastName, InitialOfFirstName”.

Input and Output Format:

Input consists of a string that corresponds to a Person’s name.

Output consists of a string(person’s name in expected format).

Refer sample output for formatting specifications.

Sample Input :

Jessica Miller

Sample Output:

Miller, J

Modify a string in Java.

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String s1 = sc.nextLine();

  public static void getvalues(String s1) {
    StringBuffer sb = new StringBuffer();
    StringTokenizer st = new StringTokenizer(s1, " ");
    String s2 = st.nextToken();
    String s3 = st.nextToken();
    sb.append(s2.substring(0, 1).toUpperCase());

Add a Comment

Your email address will not be published. Required fields are marked *

nineteen − 5 =