Results 1 to 3 of 3
Thread: Please help output not coming
- 02-05-2009, 09:09 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
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 09:47 AM. Reason: j>=0 and fin=i these both figured mtyoung thanks
- 02-05-2009, 09:20 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
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 09:32 AM.
- 02-05-2009, 09:45 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
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; rightLast edited by majin_harish; 02-05-2009 at 10:28 AM.
Similar Threads
-
Saved files are coming back as read-only
By Manoeuvre in forum EclipseReplies: 0Last Post: 11-21-2008, 05:18 PM -
Why is the answer not coming out
By anonymous18 in forum New To JavaReplies: 4Last Post: 11-12-2008, 03:10 AM -
How can i know from which jsp request is coming?
By vishnujava in forum Java ServletReplies: 1Last Post: 08-06-2008, 01:13 PM -
Name Coming Up As "null"
By sylo18 in forum New To JavaReplies: 8Last Post: 10-30-2007, 10:31 PM -
MySQL Training Class coming to Columbus, OH
By pegitha in forum Reviews / AdvertisingReplies: 0Last Post: 05-07-2007, 05:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks