Question
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class kool { public static void sortStrings(String[] arr, int n) { String
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner;
public class kool { public static void sortStrings(String[] arr, int n) { String temp; // Sorting strings using bubble sort for (int j = 0; j < n - 1; j++) { for (int i = j + 1; i < n; i++) { if (arr[j].compareTo(arr[i]) > 0) { temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } } static void printArray(String sentence) { String[] list = sentence.split(" "); for(String element: list) { System.out.println(element); } } public static void shiftRight(String[] array, int amount) { for (int j = 0; j < amount; j++) { String a = array[array.length - 1]; int i; for (i = array.length - 1; i > 0; i--) array[i] = array[i - 1]; array[i] = a; } }
public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("list.txt"));
while (input.hasNextLine()) { // Read sentence from user String sentence = input.nextLine(); // Split by " " and store to array String[] words = sentence.split(" "); int n = words.length; int shifts = words.length-1;
// char[] ch = words[0].toCharArray(); System.out.println(); // Iterare array and print senetence shiftRight(words,shifts); for (int i = 0; i < words.length; i++) { System.out.print(words[i] + " "); }
System.out.println(); sortStrings(words,n);
for(String element: words) { System.out.println(element); } }
}
}
Fix this java code so that the sort strings method sorts all the other lines not just the first one.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started