Reset author name to chosen name ✨
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>CompareSize.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}
|
||||
.ST1 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/chloe/ASDV-Java/Semester 3/Assignments/Lab_ChloeFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/chloe/lab_chloefontenot_maximumorderedstring/CompareSize.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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
<span class="literal">import</span> java.util.Comparator;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> CompareSize <span class="literal">implements</span> Comparator {
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST1">compare</span>(Object o1, Object o2)
|
||||
{
|
||||
<span class="literal">int</span> str1 = ((String) o1).length();
|
||||
<span class="literal">int</span> str2 = ((String) o2).length();
|
||||
<span class="literal">if</span> (str1 > str2) {
|
||||
<span class="literal">return</span> -<span class="number">1</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span>(str1 == str2) {
|
||||
<span class="literal">return</span> <span class="number">0</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (str1 < str2) {
|
||||
<span class="literal">return</span> <span class="number">1</span>;
|
||||
}
|
||||
<span class="literal">return</span> Integer.<span class="ST2">MAX_VALUE</span>;
|
||||
}
|
||||
|
||||
}
|
||||
</pre></body>
|
||||
</html>
|
||||
@@ -0,0 +1,74 @@
|
||||
<!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/chloe/ASDV-Java/Semester 3/Assignments/Lab_ChloeFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/chloe/lab_chloefontenot_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.chloe.lab_chloefontenot_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">chloe</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<String> possibleSubStr = <span class="literal">new</span> ArrayList<>();
|
||||
String currentStr = <span class="string">""</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < input.length() -<span class="number">2</span>; ++i) {
|
||||
currentStr = input.charAt(i) + <span class="string">""</span>;
|
||||
<span class="literal">for</span>(<span class="literal">int</span> j = i + <span class="number">1</span>; j < input.length() -<span class="number">1</span>; ++j) {
|
||||
iterationCount++;
|
||||
<span class="literal">if</span> (input.toLowerCase().charAt(i) < 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">"</span><span class="string">Iteration count: </span><span class="string">"</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("Enter a string: ");</span>
|
||||
<span class="comment">//Scanner input = new Scanner(System.in);</span>
|
||||
String inputString = <span class="string">"</span><span class="string">abcdabcdefgzabcdefadcdefab</span><span class="string">"</span>;
|
||||
<span class="comment">//input.nextLine();</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">The maximum sorted subString is: </span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="ST3">f</span><span class="ST3">indMax</span>(inputString));
|
||||
}
|
||||
}
|
||||
</pre></body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -0,0 +1,62 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>FindMaxOrderedSubstring.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.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/chloe/ASDV-Java/Semester 3/Assignments/Lab_ChloeFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/chloe/lab_chloefontenot_maximumorderedstring/FindMaxOrderedSubstring.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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
<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">ArrayList</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">Collections</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">chloe</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> FindMaxOrderedSubstring {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> String <span class="ST1">findMaxOrderedSubString</span>(String input) {
|
||||
String outputString = <span class="string">""</span>;
|
||||
<span class="literal">int</span> j = <span class="number">0</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < input.length(); ++i) {
|
||||
<span class="literal">if</span> (i == <span class="number">0</span>) {
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
<span class="literal">if</span> (input.charAt(i) > outputString.charAt(j)) {
|
||||
++j;
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
}
|
||||
<span class="literal">return</span> outputString;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
System.<span class="ST2">out</span>.println(<span class="ST3">f</span><span class="ST3">indMaxOrderedSubString</span>(<span class="string">"</span><span class="string">Welcome!</span><span class="string">"</span>));
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -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.chloe</groupId>
|
||||
<artifactId>Lab_ChloeFontenot_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.chloe.lab_chloefontenot_maximumorderedstring.Lab_ChloeFontenot_MaximumOrderedString</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public 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,47 @@
|
||||
/*
|
||||
* 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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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)
|
||||
{
|
||||
//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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class FindMaxOrderedSubstring {
|
||||
|
||||
public static String findMaxOrderedSubString(String input) {
|
||||
String outputString = "";
|
||||
int j = 0;
|
||||
for (int i = 0; i < input.length(); ++i) {
|
||||
if (i == 0) {
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
if (input.charAt(i) > outputString.charAt(j)) {
|
||||
System.out.println(++j);
|
||||
outputString += input.charAt(i);
|
||||
}
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a string: ");
|
||||
String inputStr = input.nextLine();
|
||||
System.out.println(findMaxOrderedSubString(inputStr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
import java.util.Comparator;
|
||||
|
||||
public class GenericMergeSort {
|
||||
|
||||
public static <E extends Comparable<E>> void mergeSort(E[] list)
|
||||
{
|
||||
mergeSort(list,
|
||||
new Comparator<E>() {
|
||||
@Override
|
||||
public int compare(E e1, E e2)
|
||||
{
|
||||
return ((Comparable<E>) e1).compareTo(e2);
|
||||
}
|
||||
});
|
||||
}
|
||||
static int recursiveCallCount = 0;
|
||||
public static <E> void mergeSort(E[] list,
|
||||
Comparator<? super E> comparator)
|
||||
{
|
||||
|
||||
if (list.length > 1) {
|
||||
recursiveCallCount++;
|
||||
// Merge sort the first half
|
||||
E[] firstHalf = (E[]) new Object[list.length / 2];
|
||||
System.arraycopy(list, 0, firstHalf, 0, list.length / 2);
|
||||
mergeSort(firstHalf, comparator);
|
||||
|
||||
// Merge sort the second half
|
||||
int secondHalfLength = list.length - list.length / 2;
|
||||
E[] secondHalf = (E[]) new Object[secondHalfLength];
|
||||
System.arraycopy(list, list.length / 2,
|
||||
secondHalf, 0, secondHalfLength);
|
||||
mergeSort(secondHalf, comparator);
|
||||
|
||||
// Merge firstHalf with secondHalf
|
||||
E[] temp = merge1(firstHalf, secondHalf, comparator);
|
||||
System.arraycopy(temp, 0, list, 0, temp.length);
|
||||
}
|
||||
}
|
||||
|
||||
private static <E> E[]
|
||||
merge1(E[] list1, E[] list2, Comparator<? super E> comparator)
|
||||
{
|
||||
E[] temp = (E[]) new Object[list1.length + list2.length];
|
||||
|
||||
int current1 = 0; // Index in list1
|
||||
int current2 = 0; // Index in list2
|
||||
int current3 = 0; // Index in temp
|
||||
|
||||
while (current1 < list1.length && current2 < list2.length) {
|
||||
if (comparator.compare(list1[current1], list2[current2]) < 0) {
|
||||
temp[current3++] = list1[current1++];
|
||||
} else {
|
||||
temp[current3++] = list2[current2++];
|
||||
}
|
||||
}
|
||||
|
||||
while (current1 < list1.length) {
|
||||
temp[current3++] = list1[current1++];
|
||||
}
|
||||
|
||||
while (current2 < list2.length) {
|
||||
temp[current3++] = list2[current2++];
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Integer[] list
|
||||
= {
|
||||
2, 3, 2, 5, 6, 1, -2, 3, 14, 12
|
||||
};
|
||||
mergeSort(list);
|
||||
System.out.println("number of recursive calls: " + recursiveCallCount);
|
||||
recursiveCallCount = 0;
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
System.out.print(list[i] + " ");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
String[] list1
|
||||
= {
|
||||
"ABC", "abc", "abm", "Anf", "Good", "Bad", "nice"
|
||||
};
|
||||
mergeSort(list1, (s1, s2) -> s1.compareToIgnoreCase(s2));
|
||||
System.out.println("number of recursive calls: " + recursiveCallCount);
|
||||
recursiveCallCount = 0;
|
||||
for (int i = 0; i < list1.length; i++) {
|
||||
System.out.print(list1[i] + " ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class JudeFindMax {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(consecLetters("abcabcdgabxy"));
|
||||
System.out.println(consecLetters("abcabcdgabmnsxy"));
|
||||
System.out.println(consecLetters("abchjsfhajshfhijklmnopqjfaksfhkajhsf"));
|
||||
System.out.println(consecLetters("hnafffgardghikortmmnmnmn"));
|
||||
}
|
||||
|
||||
public static String consecLetters(String input)
|
||||
{
|
||||
String consec = "";
|
||||
String maxConsec = "";
|
||||
|
||||
for (int i = 1; i < input.length(); i++) //n - 1
|
||||
{
|
||||
//If two in order
|
||||
if (input.charAt(i) > input.charAt(i - 1))
|
||||
{
|
||||
//If length is zero then add previous as well
|
||||
if (consec.length() == 0)
|
||||
consec += input.charAt(i - 1);
|
||||
consec += input.charAt(i);
|
||||
}
|
||||
//If not in order
|
||||
else
|
||||
{
|
||||
//Check current consec length against maximum length
|
||||
if (consec.length() > maxConsec.length())
|
||||
{
|
||||
//set new max
|
||||
maxConsec = consec;
|
||||
}
|
||||
consec = "";
|
||||
}
|
||||
}
|
||||
|
||||
//Check current consec length against maximum length
|
||||
if (consec.length() > maxConsec.length())
|
||||
{
|
||||
//set new max
|
||||
maxConsec = consec;
|
||||
}
|
||||
|
||||
return "Most letters found in order: " + maxConsec;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.chloe.lab_chloefontenot_maximumorderedstring;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab_ChloeFontenot_MaximumOrderedString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user