Your Only Destination To Empower Your Computer Programing Knowledge. Sky is not so high, You can Touch it if You Try

Program to find reverse of a string but returning in same order

import java.util.*;
class Reverse
{

public static void main(String fj[])
{
int b=0,j=-2,j1;
Scanner s1=new Scanner(System.in);
System.out.println("\nEnter the string");
String str=s1.nextLine();
int v=0;
System.out.println("\n\n");
for(int i=0;i {
int r=str.charAt(i); if((((int)r)==32)||(i==(str.length()-1)))
{
j++;
for(j1=j;j1>=b;j1--)
{
System.out.print(str.charAt(j1));
}
System.out.print(" ");
j++;
b=j;
}
else
{
j++;

}

}

System.out.println("\n\n");
}
}

Output:-


C:\Documents and Settings\Administrator>cd\

C:\>cd java

C:\java>cd bin

C:\java\bin>javac Reverse.java

C:\java\bin>java Reverse

Enter the string
MEENAKSHI SHARMA



IHSKANEEM AMRAHS

No comments:

Post a Comment