2023-11-15 10:17:04 -06:00

75 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>FindMax.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.Collections;
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">util</span><span class="comment">.</span><span class="comment">Comparator</span><span class="comment">;</span>
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">util</span><span class="comment">.</span><span class="comment">Scanner</span><span class="comment">;</span>
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> FindMax {
<span class="literal">public</span> <span class="literal">static</span> String <span class="ST1">findMax</span>(String input) {
<span class="literal">int</span> iterationCount = <span class="number">0</span>;
ArrayList&lt;String&gt; possibleSubStr = <span class="literal">new</span> ArrayList&lt;&gt;();
String currentStr = <span class="string">&quot;&quot;</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; input.length() -<span class="number">2</span>; ++i) {
currentStr = input.charAt(i) + <span class="string">&quot;&quot;</span>;
<span class="literal">for</span>(<span class="literal">int</span> j = i + <span class="number">1</span>; j &lt; input.length() -<span class="number">1</span>; ++j) {
iterationCount++;
<span class="literal">if</span> (input.toLowerCase().charAt(i) &lt; input.toLowerCase().charAt(j)) {
currentStr += input.charAt(j);
} <span class="literal">else</span> {
possibleSubStr.add(currentStr);
<span class="literal">break</span>;
}
}
}
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Iteration count: </span><span class="string">&quot;</span> + iterationCount);
System.<span class="ST2">out</span>.println(possibleSubStr);
Collections.<span class="ST3">sort</span>(possibleSubStr, <span class="literal">new</span> CompareSize());
<span class="literal">return</span> possibleSubStr.get(<span class="number">0</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args)
{
<span class="comment">//System.out.print(&quot;Enter a string: &quot;);</span>
<span class="comment">//Scanner input = new Scanner(System.in);</span>
String inputString = <span class="string">&quot;</span><span class="string">abcdabcdefgzabcdefadcdefab</span><span class="string">&quot;</span>;
<span class="comment">//input.nextLine();</span>
System.<span class="ST2">out</span>.print(<span class="string">&quot;</span><span class="string">The maximum sorted subString is: </span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(<span class="ST3">f</span><span class="ST3">indMax</span>(inputString));
}
}
</pre></body>
</html>