FindMax
This commit is contained in:
parent
9ef4210608
commit
d6217db9e9
1
.gitignore
vendored
1
.gitignore
vendored
@ -193,3 +193,4 @@
|
|||||||
/Semester 3/Assignments/LinkedList/nbproject/private/
|
/Semester 3/Assignments/LinkedList/nbproject/private/
|
||||||
/Semester 3/Assignments/LinkedList/build/
|
/Semester 3/Assignments/LinkedList/build/
|
||||||
/Semester 3/Assignments/MP6_CalebFontenot/target/
|
/Semester 3/Assignments/MP6_CalebFontenot/target/
|
||||||
|
/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/target/
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>edu.slcc.asdv.caleb</groupId>
|
||||||
|
<artifactId>Lab_CalebFontenot_MaximumOrderedString</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>20</maven.compiler.source>
|
||||||
|
<maven.compiler.target>20</maven.compiler.target>
|
||||||
|
<exec.mainClass>edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring.Lab_CalebFontenot_MaximumOrderedString</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class FindMax {
|
||||||
|
public static String findMax(String input) {
|
||||||
|
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) {
|
||||||
|
if (input.toLowerCase().charAt(i) < input.toLowerCase().charAt(j)) {
|
||||||
|
currentStr += input.charAt(j);
|
||||||
|
} else {
|
||||||
|
possibleSubStr.add(currentStr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(possibleSubStr, new CompareSize());
|
||||||
|
//System.out.println(possibleSubStr);
|
||||||
|
return possibleSubStr.get(0);
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
//System.out.print("Enter a string: ");
|
||||||
|
//Scanner input = new Scanner(System.in);
|
||||||
|
String inputString = "abcdabcdefgzabcdefadcdefab";
|
||||||
|
//input.nextLine();
|
||||||
|
System.out.print("The maximum sorted subString is: ");
|
||||||
|
System.out.println(findMax(inputString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class CompareSize implements Comparator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Object o1, Object o2)
|
||||||
|
{
|
||||||
|
int str1 = ((String) o1).length();
|
||||||
|
int str2 = ((String) o2).length();
|
||||||
|
if (str1 > str2) {
|
||||||
|
return -1;
|
||||||
|
} else if(str1 == str2) {
|
||||||
|
return 0;
|
||||||
|
} else if (str1 < str2) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class Lab_CalebFontenot_MaximumOrderedString {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user