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
Anyone who uses Edmentum Plato homeschool can anyone please help me my biology is not loading and it says flash is not available
Pavlova-9 [17]
Turn off your computer, wait 10 minutes, turn it back on. Open your browser, and go to the website. If it is still not working, I would assume that this is not a problem with your computer, but the network was not loaded properly, and should be fixed with some patience. In the mean time, you may have the day off.
8 0
4 years ago
Read 2 more answers
You can add multiple worksheets to a workbook by clicking the home tab on the ribbon, pressing and holding ____, and then clicki
koban [17]
<span>You can add multiple worksheets to a workbook by clicking the home tab on the ribbon, pressing and holding shift , and then clicking the number of existing worksheet tabs that correspond with the number of sheets you want to add, clicking the insert list arrow in the cells group on the home tab, then clicking insert sheet.</span>
4 0
3 years ago
When should you use an array in developing a program? Explain why it is important to apply arrays in a program.
agasfer [191]

Answer:

The answer is below

Explanation:

There are various reasons to apply arrays in a program. Some of which includes:

1. Arrays provides users to easily save specified numbers of the element in them.

2. It easily store data of similar types and sizes.

3. It allows users to store data in various dimensional arrays.

4. It eliminates deficit of memories for the location of its elements

5 0
3 years ago
Draw a Hierarchical input process output ( HIPO ) chart to represent a high - level view of the functions of the proposed system
Morgarella [4.7K]

The format to use in drawing the Hierarchical input process output  chart to show a high - level view of the functions of the proposed system is given in the image attached.

<h3>What is hierarchical input process output?</h3>

An HIPO model is known to be a form of hierarchical input process output model that helps in  systems analysis design and also in documentation .

Note that it is often used for depicting the modules of a system based on the use of hierarchy and for saving each module and thus by following the method used in the image attached, one can draw a Hierarchical input process output ( HIPO ) chart to represent a high - level view of the functions of the proposed system.​

Learn more about HIPO  from

brainly.com/question/2665138

#SPJ1

5 0
2 years ago
1. Explain what is meant by the following data types:
Colt1911 [192]
An Integer in an object that represent an int (Integer a = new Integer(3) would represent 3).

I'm not sure about Real.

A String is an object that represents a word. (String a = "dog")

Boolean

String

int

int

Hope this kind of helps
4 0
3 years ago
Other questions:
  • How do you delete text from a slide
    14·2 answers
  • This process can be applied to help workers choose the best telecommunications technology to do a specific task.
    6·2 answers
  • Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A
    5·1 answer
  • The most complex part of ssl is the ___________ protocol.
    7·2 answers
  • If there are 1 to 30 rows the program should: Calculate and display the average of all of values read into the array Calculate a
    6·1 answer
  • What does the FixedUpdate loop do? Why do developers use it?
    14·1 answer
  • Write a script that checks to see if at least one argument has been given on the command line and tests whether the argument is
    5·1 answer
  • 4.3 mini programs AP computer science
    14·1 answer
  • Which platforms are used for mobile apps? Select 4 options.
    7·1 answer
  • Match each type of video camera to its features:
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!