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
Does a call go through on the first ring when hanging up on a house phone
Alinara [238K]
I don't think so, it doesn't on my home phone.
6 0
4 years ago
Which phone has the most GB (Gigo Bites)<br><br>A.Samsung<br>B.Iphone<br>C.LG<br>D.ZTE
Lina20 [59]
It's GigaBytes actually. And is it RAM or storage capabilities?

And also those are brands. Not models. For example, Samsung has different phones. Not just one.


7 0
3 years ago
Read 2 more answers
An online service provider provides its users with hosted​ computers, an operating​ system, and a database management system​ (D
kondaur [170]

Answer:

<em>platform as a service (PaaS)</em>

Explanation:

Platform as a Service (PaaS) <em>is a cloud services system in which a third-party vendor offers hardware and software services</em> – usually the ones required for the production of applications – to internet users.

The hardware and software are managed by a PaaS company on its own network.

As more of a consequence, PaaS helps users to access in-house technology for designing or running a new app.

8 0
3 years ago
Match the description to the step in troubleshooting.
Digiron [165]
It should go 4 5 3 2 1
5 0
3 years ago
 How do viral videos illustrate greater democracy of ideas?
irakobra [83]
I can not give you the direct answer but I can give you some ideas. The videos that go viral have an effect that makes peoples ideas clear and shows what people are into and then more people can get to know about these things.
4 0
3 years ago
Other questions:
  • Define a function below, sum_numeric_vals, which takes a single dictionary as a parameter. The dictionary has only strings for k
    12·1 answer
  • Software that protects confidentiality by screening outgoing documents to identify and block transmission of sensitive informati
    12·1 answer
  • Consider an unpipelined or single-stage processor design like the one discussed in slide 6 of lecture 17. At the start of a cycl
    10·1 answer
  • Which support function under Tech Mahindra is governing data privacy and protection related requirements
    15·1 answer
  • Que es tarjeta madre resumen porfa
    13·2 answers
  • PLZZZZZZZZZZZZZZZ HELP ME OUT!!!!! I SICK AND TIRED OF PEOPLE SKIPING MYQUESTION WHICH IS DUE TODAY!!!!
    14·1 answer
  • Colorful bead bracelet in codehs
    14·1 answer
  • X = 9 % 2if (x == 1):  print ("ONE")else:  print ("TWO")
    13·1 answer
  • Meteoroids are small space rocks. They are usually pieces of asteroids or comets. Meteoroids orbit the sun like asteroids and co
    8·1 answer
  • Give five example of a dedicated device ​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!