I need to accept a string literal and delete the first chara

I need to accept a string literal and delete the first character of each word and append it to the end of each word using Java. For example:

User enters literal: Java is awesome

It should then output new literal: avaj si wesomea.

I\'ve tried using string builder but, can\'t figure out how to do it. Thanks
I need to accept a string literal and delete the first character of each word and append it to the end of each word using Java. For example:

User enters literal: Java is awesome

It should then output new literal: avaj si wesomea.

I\'ve tried using string builder but, can\'t figure out how to do it. Thanks

User enters literal: Java is awesome

It should then output new literal: avaj si wesomea.

I\'ve tried using string builder but, can\'t figure out how to do it. Thanks

Solution

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
         //declare required variables
         Scanner read=new Scanner(System.in);
         String input=\"\",output=\"\";
         //prompt the user for inout
        System.out.print(\"Enter string literal: \");
        input=read.nextLine();
        //split input based on spaces
        String token[]=input.split(\" \");
      
        //iterate through each loop and fetch first character and append at last
        for(int i=0;i<token.length;i++)
        {
            output+=token[i].substring(1)+token[i].charAt(0)+\" \";
        }
        System.out.println(output);
     }
}

I need to accept a string literal and delete the first character of each word and append it to the end of each word using Java. For example: User enters literal

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site