/home/caleb/ASDV-Java/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
import java.util.ArrayList;
import java.util.Collections;
public class FindMax {
public static String findMax(String input) {
int iterationCount = 0;
ArrayList<String> possibleSubStr = new ArrayList<>();
String currentStr = "";
for (int i = 0; i < input.length() -2; ++i) {
currentStr = input.charAt(i) + "";
for(int j = i + 1; j < input.length() -1; ++j) {
iterationCount++;
if (input.toLowerCase().charAt(i) < input.toLowerCase().charAt(j)) {
currentStr += input.charAt(j);
} else {
possibleSubStr.add(currentStr);
break;
}
}
}
System.out.println("Iteration count: " + iterationCount);
System.out.println(possibleSubStr);
Collections.sort(possibleSubStr, new CompareSize());
return possibleSubStr.get(0);
}
public static void main(String[] args)
{
String inputString = "abcdabcdefgzabcdefadcdefab";
System.out.print("The maximum sorted subString is: ");
System.out.println(findMax(inputString));
}
}