Results 1 to 8 of 8

Thread: write a program to reverse a string with/with out reverse() method?

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Answers
    11

    write a program to reverse a string with/with out reverse() method?

    write a program to reverse a string with/with out reverse() method?


  2. #2
    Junior Member
    Join Date
    Apr 2006
    Answers
    2

    Re: write a program to reverse a string with/with out reverse() method?

    program
    REVERSE A STRING
    #include<stdio.h>
    #include<string.h>
    main()
    {
    char str[50],revstr[50];
    int i=0,j=0;
    printf("Enter the string to be reversed : ");
    scanf("%s",str);
    for(i=strlen(str)-1;i>=0;i--)
    {
    revstr[j]=str[i];
    j++;
    }
    revstr[j]='\0';
    printf("Input String : %s",str);
    printf("\nOutput String : %s",revstr);
    getch();
    }


  3. #3
    Junior Member
    Join Date
    Nov 2007
    Answers
    7

    Re: write a program to reverse a string with/with out reverse() method?

    to reverse a String using reverse() in StringBuffer

    import java.lang.String;
    import java.io.*;
    class SR{
    public static void main(String a[])throws IOException{
    String Original;
    String Reverse1;

    System.out.println("Enter a string ");

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    Original=br.readLine();
    System.out.println("Original String" + '\t' +Original);
    System.out.println("*************************");
    StringBuffer sbr=new StringBuffer(Original);

    StringBuffer sbr1=sbr.reverse();
    Reverse1=sbr1.toString();
    System.out.println("Reverse of OriginalString" +'\t' + Reverse1);
    }
    }


  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    7

    Re: write a program to reverse a string with/with out reverse() method?

    This is a prg to reverse a String with reverse() of StringBuffer and it works fine

    import java.lang.String;
    import java.io.*;
    class SR{
    public static void main(String a[])throws IOException{
    String Original;
    String Reverse1;

    System.out.println("Enter a string ");

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    Original=br.readLine();
    System.out.println("Original String" + '\t' +Original);
    System.out.println("*************************");
    StringBuffer sbr=new StringBuffer(Original);

    StringBuffer sbr1=sbr.reverse();
    Reverse1=sbr1.toString();
    System.out.println("Reverse of OriginalString" +'\t' + Reverse1);
    }
    }


  5. #5
    Junior Member
    Join Date
    Dec 2006
    Answers
    12

    Arrow Re: write a program to reverse a string with/with out reverse() method?

    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    int main()
    {
    clrscr();
    char str[10];
    char ch;
    cout<<"Enter a string: ";
    cin>>str;
    int l=strlen(str);
    for(int i=0;i<=l/2;i++)
    {
    ch=str[i];
    str[i]=str[l-1];
    str[l-1]=ch;
    l--;
    }
    cout<<"\n"<<str<<endl;
    getch();
    return 0;
    }


  6. #6
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    write a program to reverse a string with/with out reverse() method?

    //With reverse()
    -----------------------
    class ResString{
    public static void main(String args[]){
    String str=args[0];
    System.out.println("BEFORE REVERSE===="+str);
    StringBuffer strbr=new StringBuffer(str);
    strbr.reverse();
    System.out.println("After REVERSE===="+strbr);
    }
    }


    //without reverse()
    ----------------------

    lass ResString
    {
    public static void main(String args[])
    {
    for(int i=args.length-1;i>=0;i--)
    {
    for(int j=args[i].length()-1;j>=0;j--)
    {
    System.out.print(args[i].charAt(j));
    }
    System.out.print(" ");
    }
    }
    }


  7. #7
    Junior Member
    Join Date
    Jun 2007
    Answers
    7

    Re: write a program to reverse a string with/with out reverse() method?

    Quote Originally Posted by ramakris143 View Post
    write a program to reverse a string with/with out reverse() method?
    public static void main(String args[])throws IOException{
    for(int i=args.length-1;i>=0;i--){
    for(int j=args[i].length()-1;j>=0;j--){
    System.out.println(args[i].charAt(j));
    }
    }
    }


  8. #8
    Junior Member
    Join Date
    Mar 2007
    Answers
    1

    Re: write a program to reverse a string with/with out reverse() method?

    accept the input through single link list..and jusst print the list.the answer wil b the reverse of string


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact