aspose file tools*
The moose likes Java in General and the fly likes output is not coming please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "output is not coming please help" Watch "output is not coming please help" New topic
Author

output is not coming please help

harish thiru
Ranch Hand

Joined: Aug 02, 2008
Posts: 32
thanks for help but output is not coming though no runtime exceptions

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-1;
String ut=str.substring(start, fin);
rev(ut);
start=i+1;

}


}
}
}


>
harish thiru
Ranch Hand

Joined: Aug 02, 2008
Posts: 32
Oooh i am sorry i just read posting rules actually i thought they won't look after two replies i was still having problem so i again posted

i had help and now i revised my code fin=i; and j>=0;

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

avaj si doog gnimmargorp ---- output

i am having problem in reversing last word please help

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;

}


}
}
}


>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
In the future, please UseCodeTags when posting code of any length. It's unnecessarily hard to read as it is, making it less likely that people will take the time to do so.

if (str.charAt(i)==' ') {

This if condition is too strict. The body should also be executed when the end of the input string is reached. You'll possibly need to adapt indexes in that case.


Ping & DNS - my free Android networking tools app
harish thiru
Ranch Hand

Joined: Aug 02, 2008
Posts: 32
Thanks dittmer i got it but my code looks very shabby any better way i could do it

 
Don't get me started about those stupid light bulbs.
 
subject: output is not coming please help