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
Address whether each defense method listed above (single router, defense-in-depth, and demilitarized zone) is sufficiently diffe
bagirrra123 [75]

Answer:

Check the explanation

Explanation:

1) The single router approach is a security Implementation of all security policies and the defense-in depth approach employs a firewall. the DMZ approach Is establish between two routers with a firewall.

2) The single router approach is for small offices and homes.

The defense in depth approach is for large organizations.

The DMZ approach is for publicity operated networks.

3) The DMZ can provide better defense because it has more than two firewall for increased security.

5 0
4 years ago
What is the purpose of a system call in an operating system?
ikadub [295]

Answer:

 The system call is the programming way for executing the requesting the services in the program from kernel in the particular operating system.

The main purpose of the system call in the operating system is that it basically provide the different types of the services to the users by using the API (Application program interface) system.

It basically provide the interface for allowing the users to request the services between the operating system and a processor. In the linux there are basically three types of system call are as follows:

  • Fork
  • Waitpid
  • Exist

6 0
3 years ago
I want to start a debate about something
vovangra [49]

Answer:

I agree for 13-yrs old not having driving licenses because they will become a lot of wrecks and they also can kill themselves or someone and I also agree that they should not be able to get jobs because if someone stills something or a robbery happens then they could get kidnapped or they could get shot

3 0
3 years ago
Read 2 more answers
Matt Cooper of Soggy Bottom Canoe and Kayak Rental refers to concept testing as​ _____ testing.
andrezito [222]

Answer:

Beta

Explanation:

Beta testing is a Quality Assurance process, where Developers and testers evaluate the quality of application experience from the point of view of the users, who are the most important targets of any software product.

5 0
4 years ago
✨Why is among us so addictive I try to play one game but end up playing over 20✨
lapo4ka [179]

Answer:

it is i got in troble for playing it so much lol

Explanation:

sorry for the spelling

5 0
3 years ago
Read 2 more answers
Other questions:
  • Microbes that enter the body, causing disease, are<br>known as​
    13·1 answer
  • a one-two paragraph summary on the Running Queries and Reports tutorials. Apply critical thinking and an academic writing style
    6·1 answer
  • The data manipulation language (DML) of SQL contains SELECT, INSERT, DELETE, and UPDATE statements, whereas the data definition
    12·1 answer
  • PLEASE HELP SOMEONE!!!!!!!!! WILL GIVE BRAINLIEST!!!!!!!!!!!!!!!!!!!!!!!!! Fill in the blanks.
    15·1 answer
  • What does the noise reduction tool do?
    11·1 answer
  • Where Go to set up margins on a letter
    15·1 answer
  • Are Proxy Servers illegal if im using it to surpass Facebook or something because it is banned
    12·1 answer
  • Rob is planning his housewarming party. He wants to design an invitation and personalize it for each invitee. He needs to create
    11·1 answer
  • Given all of the limitations of MBR, is it still relevant in current day use?
    15·1 answer
  • *the sticker, available in the middle section of the prescription label, will indicate if the customer requested non-safety caps
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!