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
stira [4]
3 years ago
6

Write a method that accepts a string as an argument and returns a sorted string. For example, sort("acb") returns abc. Write a t

est program that reads strings from a file and writes each sorted string to a different file.
Computers and Technology
1 answer:
aalyn [17]3 years ago
5 0

Answer:

public static void sort(File nameOfFile) throws IOException {

       Scanner in = new Scanner(nameOfFile);

       File anotherFile = new File("anotherFile.txt");

       anotherFile.createNewFile();

       FileWriter fileWriter = new FileWriter(anotherFile);

       while(in.hasNextLine()){

           String word = in.nextLine().toLowerCase();

           String[] stringArray = word.split(" ");

           for(String s: stringArray){

               char[] charArray = s.toCharArray();

               Arrays.sort(charArray);

               String str = String.valueOf(charArray);

               fileWriter.write(str + " ");

           }

           fileWriter.write("\n");

       }

       fileWriter.flush();

       fileWriter.close();

   }

A complete program with a call to the the method sort is given in the explanation section

Explanation:

import java.io.*;

import java.util.Arrays;

import java.util.Scanner;

public class StringSort{

   public static void main(String[] args) throws IOException{

       File nameOfFile = new File("Myfile.txt");

       sort(nameOfFile);

   }

   public static void sort(File nameOfFile) throws IOException {

       Scanner in = new Scanner(nameOfFile);

       File anotherFile = new File("anotherFile.txt");

       anotherFile.createNewFile();

       FileWriter fileWriter = new FileWriter(anotherFile);

       while(in.hasNextLine()){

           String word = in.nextLine().toLowerCase();

           String[] stringArray = word.split(" ");

           for(String s: stringArray){

               char[] charArray = s.toCharArray();

               Arrays.sort(charArray);

               String str = String.valueOf(charArray);

               fileWriter.write(str + " ");

           }

           fileWriter.write("\n");

       }

       fileWriter.flush();

       fileWriter.close();

   }

}

You might be interested in
In a mobile phone network, how many times as strong would
steposvetlana [31]

Answer:

how many times as strong would what?

put your question in the replies to this answer and I'll gladly answer it

Explanation:

May I have brainliest please? :)

6 0
3 years ago
Take the hypothetical situation that your business is considering a move to the cloud for core systems that contain confidential
zvonat [6]

Answer:

Solutions: to have a non-related to the company account and a back-up system.

Explanation:

My proposal is to move all the information of the bussiness to the cloud for better use of the data.

This data contains confidential health and finantial information and, in order to avoid any information non-wanted exit, the account has to be completing separated from the bussiness name  (more accounts),  by this way, it will be harder for extserns to get in it and substract the confidential information.

Also, the account must have a series of  security blocks to make it harder to  enter.

Finally, in case a virus gets in it and deletes any information, the data must have a backup system that will provide all the needed information in case it goes missing.

8 0
3 years ago
Drag each label to the correct location. Each label can be used more than once. Match the device to the port through which it co
son4ous [18]

Answer:

Mouse - USB

Monitor - display port, HDMI, and thunderbolt port

External hard drive - USB and thunderbolt port

Flash drive - USB

Explanation:

A computer mouse is an input device used to interact with a computer system. It connects with the computer through the USB port.

A Monitor is an output device that is used to display information on a computer system. It can be connected to the system through the display ports, HDMI, and the thunder port.

The External hard drive is a storage device that holds data for a long period of time. It has adapters to connect to the computer through the USB ports or thunderbolt ports. The flash drive is similar in function to the hard drive but small in size and storage space. It only connects with the computer through USB ports.

5 0
3 years ago
A. which chip is thought to be the first microprocessor? how many transistors roughly did it use?
vaieri [72.5K]
A micro processor is an integrated circuit that have all the functions of a central processing unit of a computer.
The chip which is thought to be the first microprocessor is INTEL 4004. It was manufactured by Intel in 1971. Intel 4004 has 2,300 transistors. 
4 0
4 years ago
_____ consists of computer programs that govern the operation of a computer.
telo118 [61]
Hello <span>Siyujiang8092</span>

Answer: Software<span> consists of computer programs that govern the operation of a computer.

Hope that helps
-Chris</span>
6 0
4 years ago
Other questions:
  • Someone may choose to own a car instead of leasing because:
    14·2 answers
  • Consider the following relationship involving two entities, students and classes:A student can take many classes. A class can be
    9·1 answer
  • What is the correct term for a set of established guidelines for actions (which may be designated by individuals, teams, functio
    13·1 answer
  • What kind of music you guys play
    5·2 answers
  • so im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in
    13·2 answers
  • From Blown to Bits why is it important to know what children are doing on the Web Tonight?
    7·1 answer
  • PLTW activity 2.1.5 PLEASE HELP I NEED STEP 5<br> FAKE ANSWER WILL NOT BE GIVEN POINTS
    14·1 answer
  • Define a function allEqual of type ''a list -&gt; bool that will return true will all element in the input list are all equal, f
    14·1 answer
  • Select the correct answer.
    7·1 answer
  • Abby has received a request for a data set of actual data for testing a new app that is being developed. She does not want the s
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!