I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.
In other words: how could my code be more streamlined to Java?
My code:
import java.util.Scanner;
public class Main
{
private static String reverse_string(String my_string)
{
String reversed_string = "";
for(int j = my_string.length() - 1; j >= 0; j--)
{
reversed_string +== reversed_string + my_string.charAt(j);
}
return reversed_string;
}
public static void main(String[] args)
{
System.out.print("Insert a 'String': ");
Scanner input = new Scanner(System.in);
String user_string = input.nextLine().toLowerCase().replace(" ", "");
if (user_string.equals(reverse_string(user_string)))
{
System.out.println("It is a palindrome.");
} else
{
System.out.println("It is not a palindrome.");
}
}
}
I believe there are already other alternatives to my reverse_string function, hence the 'reinventing the wheel' tag.