Lập trình Java - Biểu diễn theo cấu trúc tên…họ…đệm

Viết chương trình thực hiện nhập một xâu họ tên theo cấu trúc: họ...đệm...tên; chuyển xâu đó sang biểu diễn theo cấu trúc tên…họ…đệm

Mã nguồn chương trình:


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

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ADMIN
 */
public class Bai33 {

    /**
     * @param args the command line arguments
     */
    public static String doiViTri(String strInput){
        String str= Bai31.chuanHoa(strInput);
        StringTokenizer strToken= new StringTokenizer(str," ");
        String ho    = strToken.nextToken();
        String hoDem = strToken.nextToken();
        String ten   = strToken.nextToken();
        String strOutput= ten+" "+ho+" "+hoDem;
        return(strOutput);
    }

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input= new Scanner(System.in);
        System.out.println("Nhap vao ho ten ( ho-ho dem -ten) : ");
        String strInput= input.nextLine();
        System.out.println("Ho va ten duoc sap xep lai (ten- ho - ho dem) "+doiViTri(strInput));

    }
    
}

Kết quả chạy chương trình:

Nhap vao ho ten ( ho-ho dem -ten) : 
Nguyen    Huu   Java 
Ho va ten duoc sap xep lai (ten- ho - ho dem) Java Nguyen Huu