AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-string-handling: How to reverse the String in iteration?

WAP to reverse the String in n-1 iterations. Where n is the length of input String.

corejava x 353
string-handling x 34
Posted On : 2016-06-09 22:28:41.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
up-rate
3
down-rate

Answers


import java.util.Scanner;

public class IterationReverse {
public static void main(String[] args) {
System.out.println("Please enter the input String");
Scanner input=new Scanner(System.in);
String string=input.nextLine();
System.out.println("Input String: "+string);

int length=string.length();
for(int i=1;i<length;i++){
System.out.print("Step: "+i+" ");
for(int j=length-1;j>=length-i;j--){
System.out.print(string.charAt(j));
}
System.out.println(string.substring(0,length-i));
}
}
}

Posted On : 2016-06-09 23:17:25
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188249150
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in