Answer to Question #239025 in Java | JSP | JSF for guru

Question #239025

Create a program that takes in an even sized String and prints out the first half concatenated with

original string separated by a single space.

Sample run 1:

Enter a single string: HelloThere

Output: Hello Hello There


1
Expert's answer
2021-09-18T14:07:11-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a single string: ");
        String str = scanner.nextLine();
        String resultStr = str.substring(0, str.length() / 2) + " " + str;
        System.out.println("Output: " + resultStr);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS