Write a program to take a string from the user and print it in the following way..
Example
Input- INDIA
Output-
I
N
I N D I A
I
A
Answers
Java Program
Given a string, we need to print each character of the string till its half, then print the string as a whole, and then again print each character for the other half of the string.
This is what we are going to do. Here's the program:
import java.util.Scanner;
public class Brainly
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the String: ");
String str = sc.nextLine(); //Taking User Input
int len = str.length(); //Storing length of string in len
for(int i=0;i<(int)((len/2));i++) //Running a loop for first half of str
{
System.out.println(str. charAt(i)); //Printing each character
}
System.out.println(str); //Printing full string
for(int i=(int)((len+1)/2);i<len;i++) //Running a loop for other half of str
{
System.out.println(str. charAt(i)); //Printing each character
}
}
}