i wrote this code to reverce a word but its give me a error donno why:S i hope u can help me :)

import javax.swing.JOptionPane;
public class sentence {

private static void reverse (Sentence){
	String sentence;
	sentence s = new sentence();
	sentence=("hello");
	
}


/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	
	System.out.println(reverse(sentence));
	
	
}

}

thnq

Recommended Answers

All 2 Replies

are you sure abt your code?

1. Your code would even compile
2. You are ignoring naming conventions, this could be good start
3. You are looking understanding of passing variables between method or classes private static void reverse (Sentence) wouldn't work you should be using private static void reverse (String sentence) for example
4. You would have to first send a value from main method something like

String sentence = "hello";
System.out.println(reverse(sentence));

5. You would have to either use String.toCharArray with a for loop to reverse it, or if you more clever with API documentation StringBuilder.reverse()

So try to correct your mistakes and post again if you have more problems

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.