Answer to Question #240481 in Java | JSP | JSF for Selma Shigwedha

Question #240481
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-22T03:48:09-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