0

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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by peter_budo
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.