1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ollegr [7]
3 years ago
9

A file named 'input.txt' contains a list of words. Write a program that reads the content of the file one word at a time. Check

if the word is a palindrome. If the word is a palindrome write it at the output file Output'.
Computers and Technology
1 answer:
Margarita [4]3 years ago
3 0

Answer:

// here is code in java.

import java.io.*;

import java.util.Scanner;

class Main{  

    // function to check a word is palindrome or not

 private static boolean is_Palind(String str1)

 {

     // if length of String is 0 or 1

   if(str1.length() == 0 || str1.length() == 1)

   {

     return true;

   }

   else

   {

       // recursively check the word is palindrome or not

     if(str1.charAt(0) == str1.charAt(str1.length()-1))

     {

       return is_Palind(str1.substring(1,str1.length()-1));

     }

     

     else

     {

       return false;

     }

   }

 }

// driver function

 public static void main(String[] args)

 {// variable to store word

   String word;

   // BufferedWriter object

   BufferedWriter buff_w = null;

   // FileWriter object

   FileWriter file_w = null;

   // Scanner object

   Scanner sc = null;

   try

   {

       // read the input file name

     sc = new Scanner(new File("input.txt"));

     // output file

     file_w = new FileWriter("output.txt");

     // create a buffer in output file

     buff_w = new BufferedWriter(file_w);

     

     // read each word of input file

     while(sc.hasNext())

     {

       word = sc.next();

     // check word is palindrome or not

       if(is_Palind(word))

       {

           // if word is palindrome then write it in the output file

         buff_w.write(word);

         buff_w.write("\n");

       }

     }

     // close the buffer

     buff_w.close();

     // close the input file

     sc.close();

   }

   // if there is any file missing

   catch (FileNotFoundException e) {

     System.out.println("not able to read file:");

   }

   // catch other Exception

   catch (IOException e) {

     e.printStackTrace();

   }

 }

}

Explanation:

Create a scanner class object to read the word from "input.txt" file.Read a word  from input file and check if it is palindrome or not with the help of is_Palind() function.it will recursively check whether string is palindrome or not. If it is  palindrome then it will written in the output.txt file with the help of BufferedWriter  object. This will continue for all the word of input file.

Input.txt

hello world madam

level welcome

rotor redder

output.txt

madam

level

rotor

redder

You might be interested in
What is the best programming language
pashok25 [27]

Answer:

Ther are 8 best programming language :

• Javascript

• Swift

• Scala

• Go

• Python

• Elm

• Ruby

• C#

4 0
2 years ago
Why are typewriter keys arranged the way they are?
loris [4]
They are arranged the way they are because of the QWERTY layout. It was used to slow down how people typed so they wouldn't get the typewriter jammed. Hope this helps. :)
4 0
3 years ago
Which numbering system is used for some network addresses, to describe colors
FromTheMoon [43]
Hexadecimal it describes locations in memory
5 0
3 years ago
DEFINE WHAT COPYRIGHT?
Reika [66]
Copyright is when someone is given the right to print, publish or make a film.
5 0
2 years ago
Read 2 more answers
When a support agent does not know the answer to a question, a good incident management strategy is to tell the user ____.
laiz [17]

When you don't know the answer to a question, a good incident management strategy is to tell the user that you'll research the question and get back to him or her.

<h3>What is incident management?</h3>

Incident management can be defined as a strategic process through which a business organization or company identifies, analyzes, and correct hazards, so as to ensure that normal service operation is restored as quickly as possible to end users after a disruption, as well as to prevent a re-occurrence of these hazards in the future.

As a support agent, if you don't know the answer to a question, a good incident management strategy is to tell the user that you'll research the question and get back to him or her at a latter time.

Read more on incident management here: brainly.com/question/11595883

4 0
2 years ago
Other questions:
  • What are pixels that are the exact same between multiple frames called?
    15·1 answer
  • Explain how can you protect your computer from malware
    15·2 answers
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • Kellyn needs to move Slide 8 of his presentation up so that it becomes Slide 6. What best describes how he can do this using the
    13·1 answer
  • Computer programmers often use binary codes (strings of 1s and 0s) to write programs for computers. These codes are then changed
    6·1 answer
  • What is the target audience for this poster?
    5·2 answers
  • Which is true of ASCII and Unicode?
    7·1 answer
  • Can you be my friend plz
    9·1 answer
  • You are an IT administrator troubleshooting a Windows-based computer. After a while, you determine that you need to refresh the
    10·1 answer
  • Write a function called mul_time that takes a Time_Elapsed object and a number and returns a new Time_Elapsed object that contai
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!