0

Write a program in JAVA to print the names in a hollow square form

You have to input a name (String ) and then print it in hollow square form arshav r a s h h s a r vahsra Like this 👆

8th Jun 2020, 6:30 AM
Arshav Suman
Arshav Suman - avatar
3 Answers
+ 1
import java.util.*; public class Pattern5{ public static void main(String args[]){ Scanner sc=new Scanner(System.in);int i; System.out.print("Enter a string: "); String st=sc.nextLine(); System.out.println(); StringBuffer s1=new StringBuffer(st); int p=st.length(); for(i=0;i<p;i++){ if((i%p==0) || (i+1%p==0)){ System.out.println(st); } else{ System.out.println((st.charAt(i))+" "+(st.charAt(p-1-i))); // in between there are 4 spaces . } } System.out.println(s1.reverse()); } } This is my attempt , but the output is :- Enter a string: arshav arshav r a s h h s a r v a vahsra The 2nd last line . The letters have been repeated this is my problem .
8th Jun 2020, 11:09 AM
Arshav Suman
Arshav Suman - avatar
+ 6
Please Show us your attempt.....
8th Jun 2020, 6:50 AM
ANJALI SAHU
+ 5
Hello Arshav Suman Please don't ask for codes here. If you need help please show us your attempt.
8th Jun 2020, 6:59 AM
Denise Roßberg
Denise Roßberg - avatar