Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Basics
Home > Programs > Basics

4. Write a program to reverse the string?

Answer:

<!DOCTYPE html>
<html>
<body>
<?php 
function Reverse() {
    
// input string
    
$str ="what is your name";                                     
    echo  
"Input string is :" $str."<br/>";
     
// conversion of string into array
    
$arr str_split($str); 
    
// counting lengh of array 
    
$arrlength=count ($arr); 
    
// initialising an empty array and its initial index    
    
$arrc=array(); $j=0;    
   
// loop for reading the input array    
    
for( $x$arrlength$x>=0$x--)                                                 
    {
        
// reversing the array
        
$arrc[$j]=$arr$x];                                                       
        
$j++;
    }
       
// conversion of array into string
       
$nameimplode ("",$arrc);    
       
// printing string in reverse order       
       
echo $name;                                                                        
}
Reverse();
?>  

</body>
</html>

Post Your Answer Here:

Name *
Email

rai said:Sat, April 22, 2017, 11:13:15 am

Language:

import java.util.*;
import java.lang.*;
import java.io.*;

public class ReverseString
{
    public static void main (String[] args)
    {
        String str, reverse="";
        System.out.println("Enter The String: ");
        Scanner sc=new Scanner(System.in);
        str=sc.nextLine();
        /* FIRST METHOD TO REVERSE */
        
        /* #start */
        int len=str.length();
        for(int i=len-1;i>=0;i--)
        {
            reverse =str.charAt(i);
        }
        System.out.print(reverse);
        /* #end */
        
        /* SECOND METHOD TO REVERSE */
        
        /* #start */
        char[] arr=str.toCharArray();
        for(int j=arr.length-1;j>=0;j--)
        {
            System.out.print(arr[j]);
        }
        /* #end */
        
        /* THIRD METHOD TO REVERSE*/
        
        /* #start */
        String[] arr1=str.split(" ");
        String str1="";
        for(int k=arr1.length-1;k>=0;k--)
        {
            str1 =arr1[k] " ";
        }
        System.out.println(str1);
        /* #end */
    }
}

Post Your Reply Here:



rai said:Sat, April 22, 2017, 11:13:45 am

Language:

package com.pckg;

import java.util.Scanner;

public class ReverseString {
    public static void main(String[] args) {
        System.out.println("Enter String to reverse : ");
        Scanner in = new Scanner(System.in);
        String originalString = in.nextLine();
        int len = originalString.length();
        String reverseString = "";
        for (int i = (len - 1); i >= 0; i--) {
            reverseString = reverseString   originalString.charAt(i);
        }
        System.out.println("Reverse String : "   reverseString);
    }
}

Post Your Reply Here:



monika said:Sun, June 11, 2017, 12:52:00 am

Language:

<!DOCTYPE html>
<html>
<body>
<?php 
function Reverse() {
    
// input string
    
$str ="what is your name";                                     
    echo  
"Input string is :" $str."<br/>";
     
// conversion of string into array
    
$arr str_split($str); 
    
// counting lengh of array 
    
$arrlength=count ($arr); 
    
// initialising an empty array and its initial index    
    
$arrc=array(); $j=0;    
   
// loop for reading the input array    
    
for( $x$arrlength$x>=0$x--)                                                 
    {
        
// reversing the array
        
$arrc[$j]=$arr$x];                                                       
        
$j++;
    }
       
// conversion of array into string
       
$nameimplode ("",$arrc);    
       
// printing string in reverse order       
       
echo $name;                                                                        
}
Reverse();
?>  

</body>
</html>

Post Your Reply Here:



Varun said:Thu, July 6, 2017, 9:00:45 pm

Language:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    s
    char str[100], temp;
    int i=0, j;
    printf("Enter the String : ");
    gets(str);
    i=0;
    j=strlen(str)-1;
    while(i<j)
    {
        temp=str[i];
        str[i]=str[j];
        str[j]=temp;
        i++;
        j--;
    }
    printf("Reverse of the String = %s",str);
    getch();
}

Post Your Reply Here:



Neha said:Thu, July 6, 2017, 9:00:45 pm

Language:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
    clrscr();
    char str[100], temp;
    int i=0, j;
    cout<<"Enter the String : ";
    gets(str);
    i=0;
    j=strlen(str)-1;
    while(i<j)
    {
        temp=str[i];
        str[i]=str[j];
        str[j]=temp;
        i++;
        j--;
    }
    cout<<"Reverse of the String = "<<str;
    getch();
}

Post Your Reply Here: