Question: I must design code to return an unordered set of integers in ascending and descending order in Java. I just started to code in Java

I must design code to return an unordered set of integers in ascending and descending order in Java.

I just started to code in Java using Eclipse. I am brand new to coding and need help trouble shooting my code. I must sort a set of integers in ascending and then descending order. Eclipse keeps giving me an error message saying "fw is never closed". What does this mean and how do I close fw?

Thanks in advance for any help.

package square;

import java.io.*;

I must design code to return an unordered set of integers inpublic class Integers

{

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

int[] setOfInts = {28,3,53,4,89};

int i, j, temp;

FileWriter fw;

fw = new FileWriter("sort_log.txt");

System.out.println("Sort a set of Ints");

fw.write("Unsorted set of ints ");

for (i=0; i

{

fw.write(setOfInts[i] + " ");

}

fw.write(' ');

for (j=0; j

{

for (i=0; i

{

if (setOfInts[i] > setOfInts[i+1]) {

temp = setOfInts[i];

setOfInts[i] = setOfInts[i+1];

setOfInts[i+1] = temp;

}

}

}

fw.write("Sorted set of ints ");

for (i=0; i

{

fw.write(setOfInts[i] + " ");

}

fw.close();

}

}

11 xD *Integers.java X 1 package square; 2 3 import java.io.*; 4 5 public class Integers 6 { 7 public static void main(String[] args) throws IOException { 8 int[] setofInts = {28,3,53,4,89}; 9 int i, j, temp; 10 FileWriter fw; 11 fw = new FileWriter("sort_log.txt"); 12 System.out.println("Sort a set of Ints"); 13 14 fw.write("Unsorted set of ints "); 15 for (i=0; i setOfInts[i+1]) { 26 temp = setofInts[i]; 27 setofInts[i] = setofInts [i+1]; 28 setOfInts [i+1] = temp; 29 } 30 } 31 } 32 33 fw.write("Sorted set of ints "); 34 for (i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!