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
Why would you want to minimize the Ribbon?
Yakvenalex [24]

Answer:

When the Ribbon is minimized, you see only the tabs. There is no way to delete or replace the Ribbon with the toolbars and menus from the earlier versions of Microsoft Office. However, you can minimize the Ribbon to make more space available on your screen.

7 0
3 years ago
Which of the following best explains how algorithms that run on a computer can be used to solve problems?
timama [110]

The statement which best explains how algorithms running on a computer can be used to solve problems is; D. Some problems cannot be solved by an algorithm.

<h3>What is an algorithm?</h3>

An algorithm is simply a standard formula or procedures which is made up of a set of finite steps and instructions that must be executed on a computer, so as to proffer solutions to a problem or solve a problem under appropriate conditions.

However, it should be noted that it is not all problems that can be solved by an algorithm, especially because the required parameters and appropriate conditions are not feasible or met.

Read more on algorithm here: brainly.com/question/24793921

7 0
2 years ago
Hellpppppppppppppppp
jonny [76]

Answer:

i can't see your problem

6 0
2 years ago
Read 2 more answers
The blank contains the computer's brain the central processing unit CPU
Mila [183]

The Motherboard contains the computer's brain which is the Central Processing Unit (CPU).  It is the main circuit board for the computer, containing both soldered, non removable components along with sockets or slots for components that can be removed. The motherboard holds the CPU, RAM and ROM chips, etc.

7 0
3 years ago
study the picture of the simulation and the graph above. based on the information obtained from your study of the simulation and
andreyandreev [35.5K]
This is how you know i’m def gonna fail my university class this year :/
6 0
3 years ago
Other questions:
  • Change control in application development is a formal process for changing written documentation into online documentation, and
    13·1 answer
  • The trim video feature allows you to trim your clip by time measurements that are accurate to ____ of a second.
    5·1 answer
  • By using the search functionality within a twitter stream, users can filter for:
    9·1 answer
  • What is the term for the error caused when one end of an unshielded twisted-pair (UTP) cable is terminated in the T568A configur
    6·1 answer
  • HELP ASAP 10 POINTS COMPUTER SCIENCE
    14·2 answers
  • Which of these is a negative effect of computer technology's role in creating
    9·1 answer
  • Write the function evens which takes in a queue by reference and changes it to only contain the even elements. That is, if the q
    6·1 answer
  • Random.choice will choose a number between 1 and 100. True False​
    6·1 answer
  • which of the following protocols allows hosts to exchange messages to indicate problems with packet delivery?
    14·1 answer
  • Mention and discuss specific professional ethics related to augmented reality, artificial intelligence, and the internet of thin
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!