Reputation: 1
public class Key {
public Encode() {
StringBuffer passWord = new StringBuffer("bubbles");
System.out.println("Original plain text:" + passWord);
for (int i = 0; i < passWord.length(); i++) {
int temp = 0;
temp=(int)passWord.charAt(i);
temp= temp* 9;
EncodedText = passWord.setCharAt(i , (char)temp);
return EncodedText;
}
//return EncodedText;
}
}
Just writing a small program to encode (and decode) a small piece of text, but whenever I run it the same error message appears
"error: invalid method declaration; return type required public Encode() { " ^
Upvotes: 0
Views: 202
Reputation: 4730
Also you are not following proper Java naming-convention. It should be like:
public returnType methodName(dataType parameter1, dataType parameter2){
}
e.g.
public int add(int a, int b){
return a+b;
}
for naming convention standards, refer: http://java.about.com/od/javasyntax/a/nameconventions.htm
Upvotes: 0
Reputation: 8246
Your method has no return type. It needs this so that it knows what type of data it returns.
public <type goes here> Encode() {
This
EncodedText = passWord.setCharAt(i , (char)temp);
Doesn't make sense. EncodedText
is a class, it needs an instance before you assign to it. Should maybe be
EncodedText variableName = passWord.setCharAt(i , (char)temp);
But is probably more like (I don't know without seeing that class)
EncodedText variableName = new EncodedText(passWord.setCharAt(i , (char)temp));
And this
return EncodedText;
Also doesn't make sense, this is trying to return a class, perhaps you meant to return the instance of the class
return variableName;
in which case, in the first error, you probably meant
public EncodedText Encode() {
Other than that, there are a few other errors I can't properly diagnose without seeing the EncodedText
class. Errors like returning while in a loop that seems to be building an EncodedText
object and lack of creation of said object.
Upvotes: 1
Reputation: 337
You need to put a return type (such as String, int, double, etc.), probably StringBuffer in this case, between the public
and Encode()
. Try doing public StringBuffer Encode() {...}
Upvotes: 0
Reputation: 3822
You have several errors here.
return
in the for loop, it makes the loop useless as it will return in the first iteration.setCharAt()
has void as return type, you can not assign it to a variable.Upvotes: 0