Write a program to find length of string and print second half of the string

Write a program to find length of string and print second half of the string

Write a program to find length of string and print second half of the string

Explanation :

Hello friends welcome again i hope you all like my explanation, so Let’s begin with our today’s program

so you have to write program to find length of string and print second half of the string (we have to take string from user)

so now let’s discuss the logic, how you can implement it

you have to take string from user so you have to make use of Scanner class and store the user input in string variable “string

note : make sure you use of next() or nextline() for scanning user input

Now make use of length() to find length of the string  [Ex: string.length() ; ]

then divide the string length by 2 to find exact half of string and pass the result in substring()

[Ex: string.substring(string.length()/2) ]

that’s all now print the resultant string using System.out.println(); 

program is given below follow it for reference

Check Out other post – Write a program to enter two numbers and perform mathematical operations on them

if you like the the way of explanation tell us in comment section you can also write the queries about this program we are defiantly going reply

share this post with your college friends so everyone can get benefit of it good bye friends see you in next post happy coding

Program As per GTU Syllabus

Program :

OUTPUT :

Write a program to find length of string and print second half of the string

 

 

 

 

 

 

You May Also Like

About the Author: TheCoder

Leave a Reply

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