To find palindrome no in a file

To find palindrome no in a file

View Answers

April 14, 2009 at 10:10 AM

Hi Prashant,

Use the following code:

import java.util.Scanner;
import java.io.File;

public class palindromeExample {
static int counter;
public static boolean isPalindrome (String s) {
int low, high;
low = 0;
high = s.length()-1;
while (low<high) {
if (s.charAt(low) != s.charAt(high)) {
return false;
}
low++;
high--;
}
counter++;
return true;
}
public static void main(String args[]) throws Exception {
File infile = new File("C://Hello.txt";);
Scanner input = new Scanner( infile );
while (input.hasNext()) {
String word = input.nextLine();

if (isPalindrome(word)) {
System.out.printf("Found a palindrome: %s\n", word);
}
}
System.out.println("Number of Palindromes in the file: "+counter);
input.close();
}
}
Thanks









Related Tutorials/Questions & Answers:
To find palindrome no in a file - Java Beginners
To find palindrome no in a file  hi all i am having a problem...I wanted to write one java program where i have to count the no of palindrome in a file. I tried it with my own but not able to get result.pls help me out  
palindrome
palindrome  program to find the given string is palindrome or not   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.... is palindrome"); } else{ System.out.println("String is not palindrome
Advertisements
Palindrome
Palindrome  program to verify palindrome
Find Numbers which are palindrome and prime
Find Numbers which are palindrome and prime In this section, you will learn how to find the numbers from 1 to 500 which are palindrome and prime. To compute...() of boolean type. Now the list contains all the numbers which are palindrome
PALINDROME
PALINDROME  how to find palindrome of a number WITHOUT using a string... == reversedNumber){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"); } } catch(Exception e){ System.out.println(e
palindrome
palindrome  write a program to print palindrome numbers between 500 to 700
palindrome
palindrome  how to write in string of palindrome?   import... is palindrome"); } else{ System.out.println("String is not palindrome
palindrome
palindrome  how to write in string of palindrome   import... is palindrome"); } else{ System.out.println("String is not palindrome
java palindrome
java palindrome  sir i need java program to print 1)integer palindrome 2)string palindrome
How to find a config file in spring project
How to find a config file in spring project  how to find configuration file in the spring project
how to find which user has modified the file
how to find which user has modified the file  how to find which user has modified the file
Find the percentage of words which starts with a vowel in a file
Find the percentage of words which starts with a vowel in a file   Question: Find the percentage of words which starts with a vowel in a file. Ex: Input: Contents of File1- There is an endless loop in the program. Output: Vowel
Program to find no of metrics in a file ----- Java code
Program to find no of metrics in a file ----- Java code  Hi Friends, I got a task to calculate the metrics of a program, like to find... the no of SELECT and INSERT statements but unable to find tablewise. E.G Table
find zip file length lessthen 5MB
find zip file length lessthen 5MB  import java.io.BufferedReader... File folder = new File(source); if(folder.exists... :"); detination=readkeyboard.readLine(); File[] files
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util.*; import java.io.*; public class countunique { private String[] splitter...())); } System.out.println("Number of unique words in file "+cc
prime palindrome
prime palindrome  Hi I want to write a program in pascal that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. thks
prime palindrome
prime palindrome  Hi I want to write a program that ask a user to input a number, the program then list all the prime numbers that are palindrome below the number entered. In pascal language Thanks
Find the date of the file before the file has been modified
Find the date of the file before the file has been modified  Hi, may i know is it possible to find the date of the file before the file has been modified?   hi friend, you can get the date of last modified file using
complete the code (palindrome) - Java Beginners
complete the code (palindrome)  Write a program that checks if a word is palindrome. A word is said to be palindrome if it reads the same forward...: noon noon is a palindrome. Enter a word: moon moon is not a palindrome
Error 500-Server are not find the jar file in the program of upload the file - JSP-Servlet
Error 500-Server are not find the jar file in the program of upload... a program to upload a file.I include the commons-fileupload-1.2.1.jar file in lib...); // Create a new file upload handler System.out.println(isMultipart); DiskFileUpload
To check a palindrome number?
To check a palindrome number?  program to check a number is palindrome or not using recursion?(wihout converting to string
ModuleNotFoundError: No module named 'palindrome'
ModuleNotFoundError: No module named 'palindrome'  Hi, My Python... 'palindrome' How to remove the ModuleNotFoundError: No module named 'palindrome' error? Thanks   Hi, In your python environment you
Need to find the position of delimiter in a file using java - Java Beginners
Need to find the position of delimiter in a file using java  Hi , will any one give me a solution to find the Need to find the position of delimiters in a file using java.Please do reply
Finding all palindrome prime numbers - Java Beginners
Finding all palindrome prime numbers  How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
palindrome - Java Beginners
palindrome  Write a program to find whether a given string is a palindrome or not  Hi Friend, Try the following code: import java.util.*; public class CheckPalindrome{ public static void main(String[] args
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
Java - search/find a word in a text file - Java Beginners
Java - search/find a word in a text file  Hello, I would like to know how to find from a list of lets say 10 but could be more, .txt files, how... want to do nothing, if FAIL, I want to record in 1 master output file, the name
palindrome - Java Beginners
palindrome  example of java program if it is a palindrome or not palindrome   Hi friend, Example to check the number is a palindrome...){ System.out.print("Number is palindrome!"); } else
palindrome - Java Beginners
is palindrome. A word is said to be palindrome if it reads the same forward... noon is a palindrome. Enter a word: moon moon is not a palindrome.  Hi...)) { System.out.println(str + " is a palindrome"); } else { System.out.println(str
palindrome - Java Beginners
palindrome  determines whether or not it is a palindrome. if the number is not five... == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"); } } catch(Exception e  
palindrome - Java Beginners
palindrome in java code  I need an example of palindrome in Java ...;& (digit2 == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"
ModuleNotFoundError: No module named 'pp-palindrome'
ModuleNotFoundError: No module named 'pp-palindrome'  Hi, My... 'pp-palindrome' How to remove the ModuleNotFoundError: No module named 'pp-palindrome' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'qq_palindrome'
ModuleNotFoundError: No module named 'qq_palindrome'  Hi, My... 'qq_palindrome' How to remove the ModuleNotFoundError: No module named 'qq_palindrome' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Trial-Palindrome'
ModuleNotFoundError: No module named 'Trial-Palindrome'  Hi, My... named 'Trial-Palindrome' How to remove the ModuleNotFoundError: No module named 'Trial-Palindrome' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'xj_palindrome'
ModuleNotFoundError: No module named 'xj_palindrome'  Hi, My... 'xj_palindrome' How to remove the ModuleNotFoundError: No module named 'xj_palindrome' error? Thanks   Hi, In your python
palindrome array problem
palindrome array problem  I'm having trouble figuring this assignment out. Can someone please help me? Generate (write the code) and save in an array Palidrome[250][5] all the 5 letter words using {a, b, c} Write the code
palindrome - Java Beginners
palindrome  import java.io.*; class Palindrome { System.out.println("Enter a word:"); BufferedReader br=new BufferedReader(new InputReaderStream(System.in)); String word; word=br.readLine(); public static void main
Java Program to check Palindrome
Java Program to check Palindrome In this section, you will learn about palindrome in java and how to check any number that is palindrome or not. First of all what is palindrome number?, this is the number that the original number
Palindrome Number Example in Java
Palindrome Number Example in Java    ... the palindrome number and how to determine any number is palindrome or not. First of all we are going to read about the palindrome number.  This is the number
Check whether the number is palindrome or not
Check whether the number is palindrome or not A palindrome is a word, phrase... is palindrome or not. You can check it in various ways but the simplest method...; } if (n == reversedNumber) { System.out.print("Number is palindrome
.jar file keeps giving me " could not find the main class". Program will exit.
.jar file keeps giving me " could not find the main class". Program will exit... even with a simple file that displays a jframe with a jlabel on it. My... clean and build it which produces a .jar file in my dist folder. When I double
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program. In this section you will read how to uses palindrome one dimensional array
Palindrome program in Java
Palindrome program in Java helps programmers to determine if a number or string is palindrome or not. palindrome number or string remains unchanged when.... The logic used in Java program behind finding a number or sting is palindrome
Check whether the sum of alternate digit of a number is palindrome or not.
by the user is palindrome or not. So, firstly we have to find the sum...Check whether the sum of alternate digit of a number is palindrome... of this number be 2+4+6 i.e 12) and then check whether this sum is palindrome
how to write a function to print for finding the longest palindrome in the given string
how to write a function to print for finding the longest palindrome in the given string  how to write a function to print for finding the longest palindrome in the given string
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please explain me the logic with an example   import java.util.*; public
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..
i want to find the byte code of a image file ... for my project..plz if anybody... a image file to its byte code format that help me for the pattern matching in my project.. but i cant convert Image file to its byte code format.. if anybody can plz
Finding Last Modification Date of a file
This section contains the detail about how to get the last modification date of a file. This can be done by creating instance of the file using File Class...) { File file = new File("DevFile.txt"); Long LM = file.lastModified
Java latest file
Java latest file In this section, you will learn how to find the file which is generated or modified at last. Description of code: To find the last modified file, we have used the Comparator interface that compare the files 
Java file modified date
Java file modified date In this section, you will learn how to find the modification date and time of the file. Description of code: We have created an instance of File class and specify the file. Then, we have checked whether

Ads