Java reverse String and simplest palindrome checker

Today, i have learn something new and it's totally simple. Sometime when don't know about that, we will use our way that take a time to complete a simple task. What i learn today is, how to reverse String. The easiest way to reverse a String for example from "i love you" to "uoy evol i" is using method reverse() in StringBuffer class. It is also very useful especially when you want to create a palindrome checker program. Your program will be the shortest palindrome checker program in the world i think, hehehehe. I have also created a new one before, but it quit long. You can review it by click here. Now we will go to coding part. I will create two simple programs. Firstly to reverse "i love you" to "uoy evol i". Secondly i will create my shortest palindrome checker program that i ever made. Don't waste our time by hear what i said.

*************************************************************
COMPLETE SOURCE CODE FOR : ReverseString.java
*************************************************************


public class ReverseString
{
public static void main(String[]args)
{
String a="i love you";
StringBuffer b=new StringBuffer(a);

System.out.println(b.reverse());
}
}


*************************************************************
LIKE USUAL, JUST COMPILE AND EXECUTE IT
*************************************************************

*************************************************************
COMPLETE SOURCE CODE FOR : MySimplestPalindromeChecker.java
*************************************************************


import javax.swing.JOptionPane;

public class MySimplestPalindromeChecker
{
public static void main(String[]args)
{
String a=JOptionPane.showInputDialog(null,"What word that you want to check ?","Palindrome Checker",JOptionPane.QUESTION_MESSAGE);

if(a!=null)
{
String b=a;
StringBuffer c=new StringBuffer(b);
if(a.equals(c.reverse().toString()))
{
JOptionPane.showMessageDialog(null,"THIS IS A PALINDROME WORD");
}
else
{
JOptionPane.showMessageDialog(null,"THIS IS NOT A PALINDROME WORD");
}
}
}
}


*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************

Square root symbol in java

After i spend a day to find how to print square root symbol in java through command prompt, someone tell me from java forum if our command prompt did not have a glyph for the square root character, this job will undone. But when i try use it in JOptionPane's message box it perform well.

In java "\u221A" is refer to square root symbol. It is Unicode.You can try to visit link below for more details :
Click here

If you want to print square root symbol through your command prompt, you can try something like this. I hope your command prompt can support for this thing.


public class Test2
{
public static void main(String[]args)
{
System.out.println("\u221A");
}
}


If you want to put it in JOptionPane's message box (this is perform well in my computer), you can try this :


import javax.swing.JOptionPane;

public class Test2
{
public static void main(String[]args)
{
JOptionPane.showMessageDialog(null,"\u221A");
}
}

RELAXING NATURE VIDEO