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 a detailed and thorough review of the deployed security infrastructure compared with the organization’s security policy
Sonbull [250]

Answer:

"Compliance audit " seems to be the correct answer.

Explanation:

  • A compliance or enforcement audit seems to be a systematic analysis of the conformity of such an agency to the reporting requirements and guidelines.
  • In a compliance audit, independent auditors determine the extent and completeness of enforcement plans, security protocols, user authentication, including risk management framework.
8 0
3 years ago
. ____________is/are the JSP ImplicitObject(s).sessionapplicationconfigAll of GivenNone of Given
Lynna [10]

Answer:

All of Given

Explanation:

JSP provides a number of implicit objects which are made available by the container and can be used directly in scriptlets. These objects include:

  • session
  • application
  • config
  • out
  • request
  • response
  • pageContext
  • page
  • exception

Example usage:

<% session.setAttribute("userid","demoid"); %>

<% application.getContextPath(); %>

<% out.println(config.getServletName()); %>

5 0
3 years ago
What kind of output device would not be used to output images
saveliy_v [14]

Answer:

Speakers.

Explanation: Cause they only output sound, and are devices, further more they are not used to output images, like how could speakers output images using sound? They can't.

3 0
3 years ago
for number in range(1,51): if number % 3 == 0 and number % 5 == 0: print('XY') elif number % 5 == 0: print('X') elif number % 3
Elza [17]

Output of the given code is:

Y

X

Y

Y

X

Y

XY

Y

X

Y

Y

X

Y

XY

Y

X

Y

Y

X

Y

XY

Y

X

Explanation:

In the for loop variable "number" will iterate from 1 to 150(inclusive).

in the "if" condition it is checking that the number is divisible by 3 and 5 both if the number is divisible by both 3 & 5 then it will print XY as output.

In the first "elif", if the number is divisible by 5 only then it will print X

as output.And in the last "elif", if number is divisible by 3 only then it will

print Y as output. Nothing will be printed if all three conditions are FALSE.

7 0
4 years ago
An electrician uses a device called a volt meter. The volt meter is an example of
kirill115 [55]

Answer:

hardware

Explanation:

A voltmeter can be defined as an electrical device used for measure voltage level or the amount of voltage present in a circuit.

In this scenario, an electrician uses a device called a volt meter. The volt meter is an example of hardware.

A hardware refers to any device, machine or equipment that can be handled physically (touched) and seen with the naked eyes. Other hardware components of a computer includes monitor, speaker, central processing unit, motherboard, hard-drive, joystick, mouse, keyboard, etc.

On the other hand, software component of a computer comprises of software application or program that are used by the computer to manage or control software application, computer hardware and user processes. Some examples of software components are operating system, registry keys, antivirus, media player, word processor, etc.

4 0
3 years ago
Other questions:
  • An administrator working on a Windows Server 2016 Server Core installation needs to disable DHCP on all interfaces on the server
    12·1 answer
  • When advising a customer on the purchase of a new power supply, you should explain that if the power supply runs at peak perform
    9·1 answer
  • How can you tell if a motherboard can be watercooled?
    13·1 answer
  • Which is NOT a joint?<br> A. <br> Femur<br> B. <br> Knee<br> C. <br> Elbow
    13·2 answers
  • What is the most secure method for controlling privileged access to a system available for use in a public area?a. Database view
    5·1 answer
  • An individual posing as an online gamer accesses information stored in an unsuspecting user’s computer by placing a program in h
    11·1 answer
  • When I’m design view, Henrietta deleted a previous criterion, added a new column, and filtered patients’ age. Which best describ
    15·1 answer
  • PowerPoint SAM Capstone Project 1 can PLEASE someone do it for me I have some directions like steps and you just have to do it i
    10·2 answers
  • From the philosophical standpoint, especially in the discussion of moral philosophy or ethics, why do we consider “murder” or “k
    9·1 answer
  • Which communication network pattern offers a fairly even flow of information, but two people interact with only one other?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!