Here use StringBuffer class and create object name[] of StringBuffer class. Use method reverse() to reverse inserted string.
Program Code
//developed by Om Prakashimport java.util.*;
class StringReverse
{
public static void main(String argv[])
{
int size;
Scanner console=new Scanner(System.in);
System.out.println("*******STRING REVERSE*******");
System.out.print("How many string do you want to enter : ");
size=console.nextInt();
StringBuffer name[]=new StringBuffer[size+1];
String temp;
int i;
System.out.println("Enter "+size+" string : ");
for(i=0;i<=size;i++)
{
temp=console.nextLine();
name[i]=new StringBuffer(temp);
}
System.out.println("String after Reverse");
for(i=0;i<=size;i++)
{
name[i].reverse();
System.out.println(name[i]);
}
}
}
No comments:
Post a Comment
Dont SPAM