import javax.swing.*;


class ch9reverse{


public static void main (String [] args){

int Character,
count = 0;

char letter;

String Str;
Str = "The gate to Java nirvana is near"; For this must print out the "ehT etag ot avaJ anavrin si raen
Character = Str.length();


System.out.print(reverseString(Str));

tokenize the sentence by using space as a delimiter, save each letter in an array then print out the result in reverse

import javax.swing.*;


class ch9reverse{


public static void main (String [] args){

int Character,
count = 0;

String Str;
Str = "The gate to Java nirvana is near";
Character = Str.length();


for(int i = Character-1; i >= 0; i-- ){

System.out.print(Str.charAt(i));

count ++;

}

System.out.println(count);

}
}


I kind of fix this, but it`s shows "raen si anavrin avaJ ot etag eht"


How an i make that shows "ehT etag ot avaJ anavrin si raen"


can you wirte for me?

Here's my example

String Str = "The cake is a lie"; 
char delimiter =  ' '; //the space is the delimeter

// calculate the number of delimiter characters
int N = 0;
for (int i = 0; i < Str.length(); i++)
     if (Str.charAt(i) == delimiter) N++;

String[] tokens = new String[N+1];  //we add 1 for the last word
int[] tokenlength = new int[N+1];

// parse N+1 tokens and store in an array
int a = 0, b = 0;
for (int i = 0; i < N; i++) {
while(Str.charAt(a) != delimiter)
a++;
tokens[i] = Str.substring(b, a);    //saves the word in the array
tokenlength[i] = tokens[i].length();    //saves the length of the current word
a++;
b = a;
}
//For the last word
tokens[N] = Str.substring(a, Str.length());
tokenlength[N] = tokens[N].length();

// print results for testing
System.out.println(Str);
for (int i = 0; i < tokens.length; i++){
// print each tokens in reverse
for(int j = tokenlength[i]-1; j >= 0; j-- ){
System.out.print(tokens[i].charAt(j));  
}
System.out.print(" ");
} 

Also next time wrap your code in code tags

Thank you so much it is working ,
can i know about the how to write the code ?

Thank you so much it is working, can i know about the how to write the code ?

@zeroliken:
This is why you should never just post a solution to someone else's homework. You have successfully given the OP an opportunity to cheat, but taught him nothing. Next time please help the OP to learn how to solve their own problem and write their own code.

ps; If you must post code please indent it, and follow the normal Java conventions for variable names. Your post was not a good example for beginners.

I wrote it as a possible example on how to tokenize a sentence and view it in reverse where he might get a hint on how to do it by himself

sigh, looks like the intention shadowed the purpose :(

Sorry about that...I'll be more conscious next time around

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.