Write a java program to reverse string without reverse method. Write a program to read a string and a character, and reverse the string and convert it in a format such that each character is separated by the given character. Print the final string.
The return type (String) should return the final string.
Input and Output Format:
Input consists of a string and a character.
Output consists of a string (the final string).
Refer sample output for formatting specifications.
Sample Input:
Rabbit
–
Sample Output:
t-i-b-b-a-R
java program to reverse string without reverse method
package com.demo; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s1 = sc.nextLine(); reShape(s1); } public static String reShape(String s) { StringBuffer sb = new StringBuffer(s); StringBuffer sb2 = new StringBuffer(); String s2 = sb.reverse().toString(); for (int i = 0; i < s2.length(); i++) { sb2.append(s2.charAt(i)); sb2.append("-"); } sb2.deleteCharAt(sb2.length() - 1); System.out.println(sb2.toString()); return sb2.toString(); } }