Save below code as palindrome.java
CODE:
import java.util.*;
import javax.swing.JOptionPane;
class Palindrome
{
public static void main(String args[])
{
String original, reverse="";
original=JOptionPane.showInputDialog("Enter a string to check if it is a palindrome");
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
{
reverse = reverse + original.charAt(i);
}
if (original.equals(reverse))
{
JOptionPane.showMessageDialog(null,"Entered string is a palindrome","Result",JOptionPane.PLAIN_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"Entered string is not a palindrome","Result",JOptionPane.PLAIN_MESSAGE);
}
}
}
//End of program
Output:
To run this java program you should first install jdk(Java Development kit).
you can download it from here.
And also can download this java code and directly execute by simply clicking on .bat file in the rar file downloaded
Download here
Password for rar is:letuscodeit
Know about:
-JOptionPane
CODE:
import java.util.*;
import javax.swing.JOptionPane;
class Palindrome
{
public static void main(String args[])
{
String original, reverse="";
original=JOptionPane.showInputDialog("Enter a string to check if it is a palindrome");
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
{
reverse = reverse + original.charAt(i);
}
if (original.equals(reverse))
{
JOptionPane.showMessageDialog(null,"Entered string is a palindrome","Result",JOptionPane.PLAIN_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"Entered string is not a palindrome","Result",JOptionPane.PLAIN_MESSAGE);
}
}
}
//End of program
Output:
To run this java program you should first install jdk(Java Development kit).
you can download it from here.
And also can download this java code and directly execute by simply clicking on .bat file in the rar file downloaded
Download here
Password for rar is:letuscodeit
Know about:
-JOptionPane
No comments:
Post a Comment