Unit 2 Work
Key learnings from unit 2
public int scoreGuess(String guess)
{
int count = 0;
for (int i = 0; i <= secret.length() - guess.length(); i++)
{
if (secret.substring(i, i + guess.length()).equals(guess))
{
count++;
}
}
return count * guess.length();
}
public String findBetterGuess(String guess1, String guess2)
{
if (scoreGuess(guess1) > scoreGuess(guess2))
{
return guess1;
}
if (scoreGuess(guess2) > scoreGuess(guess1))
{
return guess2;
}
if (guess1.compareTo(guess2) > 0)
{
return guess1;
}
return guess2;
}
public class Strings {
public static void main(String[] args) {
String str1 = "Hello World ";
int int1 = 1;
String str2 = ". Introducing... World ";
double double1 = 2.0;
// We now concatenate using the "+" operator for strings.
// Because Strings are immutable, this creates a new String object.
String strConcat = str1 + int1 + str2 + double1;
System.out.println(strConcat);
}
}
Strings.main(null);