I'm quite the programming beginner. I'm learning about methods and I want to know the difference between those two. Why can't I use my self made method the same way text.length(); is being used?
text.length();
text.selfMadeMethod(); instead of selfMadeMethod(text);
Edit: It seems miss wrote my example above, I'm sorry. I'll post the exercise I was working on so it can show more clearly what I tried to do.
import java.util.Scanner;
public class ReversingText {
public static String reverse(String text) {
int x = text.length() -1;
String reverse = "";
while (x >= 0) {
reverse += text.charAt(x);
x--;
}
return reverse;
}
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Type in your text: ");
String text = reader.nextLine();
System.out.println("In reverse order: " + reverse(text));
System.out.println("In reverse order: " + text.reverse());
}
}
The last print statement was just me trying that, the exercise didn't ask me to do it. Again I'm sorry if this is either a stupid question or unclear, thanks.
finalclasses).