Program to print surname from complete name

Print surname from complete name

Java program to print surname from complete name

Todays, we will try to learn split the surname from the complete name and then print on computer screen.

class Surname
 public static void main(String[] args) throws IOException
BufferedReader br=new BufferedReader(new InputStreamReader(;
String Surname="";
   System.out.print("Please Enter complete name: ");
   String Fullname=br.readLine();
String[] arr = Fullname.split(" ");
if(arr.length > 0) 
   Surname = arr[arr.length -1];
System.out.println("\nSurname: " +Surname);

Program Output:

Please Enter complete name: EduNews Tech
Surname: Tech

I hope this post helps you to understand the “Program to print surname from complete name” and its implementation in Java programming language.

Keep coding 🙂

Leave a Reply

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