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
Text messaging is an example of nonverbal communication. Please select the best answer from the choices provided. T F
Rina8888 [55]

The answer is False.  

According to research, most of what many human beings do on a daily basis is to communicate on nonverbal cues and behaviors. They include facial expressions, postures, eye gaze, tone, and voice. From the little things we do everyday like handshakes to our hairstyles, nonverbal cues reveal who we are and how we relate with others. They communicate something without the use of written or oral language.  

Text messaging is not part of any nonverbal communications. In fact, most people will argue that text messaging is hugely affecting nonverbal communications. For example, if I text you and lie to you, you will not be able to read my body position. You may believe what I am saying is true, but you cannot read it.


8 0
3 years ago
Read 2 more answers
Explain why the local disc of a computer start from C and not A​
natima [27]

Answer:

In older times, A and B drives were reserved for floppy disks or tapes. This is why C and subsequent letters are for used hard/other drives

Explanation:

7 0
3 years ago
Which of the following Internet access methods involves connecting your phone to an Internet-ready laptop in order to gain acces
weeeeeb [17]
The answer would be “4”- “Cybercafe”. Your welcome!
3 0
4 years ago
Read 2 more answers
a. a large central network that connects other networks in a distance spanning exactly 5 miles. b. a group of personal computers
ki77a [65]

Complete Question:

A local area network is:

Answer:

b. a group of personal computers or terminals located in the same general area and connected by a common cable (communication circuit) so they can exchange information such as a set of rooms, a single building, or a set of well-connected buildings.

Explanation:

A local area network (LAN) refers to a group of personal computers (PCs) or terminals that are located within the same general area and connected by a common network cable (communication circuit), so that they can exchange information from one node of the network to another. A local area network (LAN) is typically used in small or limited areas such as a set of rooms, a single building, school, hospital, or a set of well-connected buildings.

Generally, some of the network devices or equipments used in a local area network (LAN) are an access point, personal computers, a switch, a router, printer, etc.

4 0
3 years ago
Is this really a American Server ???
zloy xaker [14]

Explanation:

I am from Nepal and i don't know about this topic.

6 0
3 years ago
Other questions:
  • Which of the following refers to applications and technologies that are used to gather, provide access to, and analyze data and
    8·2 answers
  • Your computer running Windows 7 is doing some very strange things with the operating system. You are fairly certain it is not a
    10·1 answer
  • ATM is an abbreviation that stands for Automatic Teller machine?
    5·2 answers
  • 5. Write a 500- to 1,000-word description of one of the following items or of a piece of equipment used in your field. In a note
    13·1 answer
  • Assume that we are using 0-1 integer programming model to solve a capital budgeting problem and xj = 1 if project j is selected
    6·2 answers
  • Suppose that for an experimental device setup we have to choose settings for three parameters. There are 4, 3 and 5 settings for
    11·1 answer
  • Assume that Precinct Report is a structured type with these fields,address (a string),and three int fields which are counts of c
    12·1 answer
  • Can somebody help I need it now please and thank you correct answer please
    10·2 answers
  • Unicode is a world standard to represent _________________
    10·1 answer
  • Can we update App Store in any apple device. (because my device is kinda old and if want to download the recent apps it aint sho
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!