Showing posts with label string reverse. Show all posts
Showing posts with label string reverse. Show all posts

Tuesday, May 8, 2012

String Reverse Example in Java Programming

It is a sample string reverse example. In this program read array of string from user and give output array of reverse string.
Here use StringBuffer class and create object name[] of StringBuffer class. Use method reverse() to reverse inserted string.

Program Code

//developed by Om Prakash
import 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]);
}
}
}

Output





Thursday, December 15, 2011

C Program to String Reverse

It is a basic C program to reverse a string.
In this c programming example user input a string and get reverse of accepted string.

Aim - C program to reverse accepted string [Using strrev function]


Program Code
//String Reverse using strrev function
#include"stdio.h"
#include"conio.h"
#include"string.h"
void main()
{
   char str[20];
   clrscr();
   printf("********* String Reverse Using strrev Function *******\n");
   printf("Enter a string:  ");
   gets(str);
   strrev(str);
   printf("\n Reverse string is:  %s",str);
   getch();
}
Output




Aim - C program to reverse accepted string [without using strrev function]


Program Code
//String Reverse without using strrev function
#include"stdio.h"
#include"conio.h"
#include"string.h"
void main()
{
 char str1[20],str2[20];
 int i,j=0;
 clrscr();
 printf("***********String Reverse*********\n");
 printf("Enter String:");
 gets(str1);
 for(i=strlen(str1)-1;i>=0;i--,j++)
 {
  str2[j]=str1[i];
 }
 str2[j]=NULL;
 printf("\nReverse String is:");
 puts(str2);
 getch();
}

Output

Saturday, November 12, 2011

PL/SQL Program to reverse a string

This is a sample PLSQL example to accept a string from user and print reverse of accept string.

Aim - PL/SQL Program to reverse a string.



Sample PLSQL Program: -
declare
str1 varchar2(30);
len number(3);
str2 varchar2(30);
i number(3);
begin
str1:='&str1';
len:=length(str1);
for i in reverse 1..len
loop
str2:=str2 || substr(str1,i,1);
end loop;
dbms_output.put_line('Reverse string is: '||str2);
end;




Output of PL SQL Block: -
Enter value for str1: hello
old 6: str1:='&str1';
new 6: str1:='hello';
Reverse string is: olleh