Palindrome - } if (isPalindrome(inputStr)) outputStr = temp...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
_ //************************************************************* // Author D.S. Malik // // Program: Palindrome // This program determines whether an integer is a palindrome. //************************************************************* / import javax.swing.JOptionPane; i public class Palindrome { public static void main(String[] args) { long num; long temp; String inputStr; String outputStr; inputStr = JOptionPane.showInputDialog("Enter an integer, " + "positive or negative"); num = Long.parseLong(inputStr); temp = num; if (num <= 0) { num = -num; inputStr = inputStr.valueOf(num);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } if (isPalindrome(inputStr)) outputStr = temp + " is a palindrome"; else outputStr = temp + " is not a palindrome"; JOptionPane.showMessageDialog(null, outputStr, "Palindrome Program", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } public static boolean isPalindrome(String str) { int len = str.length(); //Step 1 int i, j; j = len - 1; //Step 2 for (i = 0; i <= (len - 1)/2; i++) //Step 3 { if (str.charAt(i) != str.charAt(j)) //Step 3.a return false; j--; //Step 3.b } return true; //Step 4 } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Page1 / 2

Palindrome - } if (isPalindrome(inputStr)) outputStr = temp...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online