From c7a4a36699de70f5d40dd527c7d996c1e42191b9 Mon Sep 17 00:00:00 2001 From: Frank Baumann Date: Mon, 5 May 2014 12:38:03 +0200 Subject: [PATCH] Changed words replace from while to for --- src/com/dre/brewery/Words.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/com/dre/brewery/Words.java b/src/com/dre/brewery/Words.java index dfba9b8..93428ce 100644 --- a/src/com/dre/brewery/Words.java +++ b/src/com/dre/brewery/Words.java @@ -228,14 +228,13 @@ public class Words { } // remove all "from" and split "words" there String[] splitted = words.split(from); - int index = 0; String part; // if there are occurences of "from" if (splitted.length > 1) { // - 1 because dont add "to" to the end of last part - while (index < splitted.length - 1) { - part = splitted[index]; + for (int i = 0; i < splitted.length - 1; i++) { + part = splitted[i]; // add current part of "words" to the output newWords = newWords + part; // check if the part ends with correct string @@ -247,10 +246,10 @@ public class Words { // add original newWords = newWords + from; } - index++; } + // add the last part to finish the sentence - part = splitted[index]; + part = splitted[splitted.length - 1]; if (part.equals(" ")) { // dont add the space to the end return newWords; @@ -298,5 +297,4 @@ public class Words { } } } - } \ No newline at end of file