Results 1 to 3 of 3
  1. #1
    majin_harish is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default Please help output not coming

    Read a line of text and reverse each word do not use StringTokenizer
    import java.util.*;
    public class Rev {
    static void rev(String jik){
    int i,j;

    char one[]=jik.toCharArray();
    char two[]=new char[one.length];
    for(i=0,j=one.length-1;i<one.length&&j>=0;i++,j--){
    two[i]=one[j];
    }
    String b = new String(two);

    System.out.print(b+" ");
    }
    public static void main(String[] arg){
    int i,start,fin;
    start=0;

    String str;
    Scanner in = new Scanner(System.in);
    str=in.nextLine();
    for(i=0;i<str.length();i++){
    if(str.charAt(i)==' '){
    fin=i;
    String ut=str.substring(start, fin);
    rev(ut);
    start=i+1;

    }


    }
    }
    }
    Last edited by majin_harish; 02-05-2009 at 10:47 AM. Reason: j>=0 and fin=i these both figured mtyoung thanks

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    what is your testing input?

    if your input does not contains space bar... rev would call

    and why fin = i - 1;

    and can you find any problem in for (i = 0, j = one.length - 1; i < one.length && j > 0; i++, j--)
    Last edited by mtyoung; 02-05-2009 at 10:32 AM.

  3. #3
    majin_harish is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    java is good programming language ----- sample input

    avaj si doog gnimmargorp ---- output

    yeah thanks fin=i; --- i got that

    i am having problem in getting last word please help someone teach me to properly code

    yeah i found edited also j>=0; right
    Last edited by majin_harish; 02-05-2009 at 11:28 AM.

Similar Threads

  1. Saved files are coming back as read-only
    By Manoeuvre in forum Eclipse
    Replies: 0
    Last Post: 11-21-2008, 06:18 PM
  2. Why is the answer not coming out
    By anonymous18 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 04:10 AM
  3. How can i know from which jsp request is coming?
    By vishnujava in forum Java Servlet
    Replies: 1
    Last Post: 08-06-2008, 02:13 PM
  4. Name Coming Up As "null"
    By sylo18 in forum New To Java
    Replies: 8
    Last Post: 10-30-2007, 11:31 PM
  5. MySQL Training Class coming to Columbus, OH
    By pegitha in forum Reviews / Advertising
    Replies: 0
    Last Post: 05-07-2007, 06:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •