Question
Java. Please use the list of numbers from input.txt

Objectives - practice sorting arrays - practice file 10 Description Assume there is a file called input.txt containing multip
<Back input.txt 100 91 52
(Васк input.txt


on On @ morom 0 8:55368.241 22
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.util.*;
public class abc
{
public static void main(String[] args)throws Exception
{
  

List<Integer> list = new ArrayList<Integer>();//creating an array list
File file = new File("F:\\abc\\input.txt"); //giving the path of file
  
BufferedReader br = new BufferedReader(new FileReader(file)); //using bufferedreader
FileWriter fw=new FileWriter("output.txt");//creating file variables
  
String s;
   while((s = br.readLine()) != null)
{
  
  
   //converting string to integer and adding to the list
   list.add(Integer.parseInt(s));
  

}
Collections.sort(list);// sorting the list using collections
  
for(int i : list){
fw.write(i+"\n");// writing the list into output.txt
}
fw.close();
//name the filename as the class name
}}

Add a comment
Know the answer?
Add Answer to:
Java. Please use the list of numbers from input.txt Objectives - practice sorting arrays - practice...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays....

    how do i do this in basic java without using hashmat or anything complicated Two-Dimensional Arrays. Write the three functions described below. Demonstrate that your code works by calling each function and printing out the results. All of your code should be in one file. Upload your java code and a file containing the output of running your program to show that it works. Write a function called create2DIntArray that creates a two-dimensional array of integers between 0 and 10....

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design...

    Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

  • java please Objectives To understand array To practice storing and retrieving from array To use for...

    java please Objectives To understand array To practice storing and retrieving from array To use for To manipulate multidimensional arrays Problem Specification The parking lot management will record what vehicle parked at which position. 1 2 … 10 A B C … J 1. Create an array to store the vehicles 10x10 = 100 2. Create Class vehicle Variables: String name, String manufacturer, String plate number, int parked time (Hour 00 - 24), String position (A1, A2 …) Functions: getName(),...

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

  • The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain...

    The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain an understanding and experience with stacks. Gain further experience using generics. Continue to practice good programming techniques. Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation. void push(E item) push item onto top of stack E peek() return item on top of stack E pop() return item on top...

  • Please go to the Practice Exercises (at the end of Chapter 3 in your text on...

    Please go to the Practice Exercises (at the end of Chapter 3 in your text on page 129) and do Exercise E 3.14 which asks you to compute and print the current season of the year depending on the month and day (input as integers). Be sure to review Java boolean operators, multi-way IF-ELSE statements, Switch statements, and String comparison methods before implementing your Java code. The algorithm for this program has been written for you and is included in...

  • write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.t...

    write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.txt and all output will go to the screen Assume there will not be more than 100 7 23.56 16 88.12 10 75.1 Design a Java class with a main method that does the following 1) Reads the data into two arrays of doubles,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT