This repository has been archived on 2026-10-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
projectstem-keys-java/FRQs/2015 Practive Exam FRQ.java
2024-06-13 08:40:42 -07:00

41 lines
1.2 KiB
Java

// Online Java Compiler
// Use this editor to write, compile and run your Java code online
public static class HiddenWord {
private String word;
public HiddenWord(String word) {
this.word = word;
}
public String getHint(String guess) {
String result = "";
for(int i = 0; i < guess.length() - 1; i++) {
String char1 = word.substring(i, i + 1);
String char2 = guess.substring(i, i + 1);
boolean isInWord = false;
for(int j = 0; j < word.length() - 1; j++) {
String char = word.substring(i, i + 1);
if(char.equals(char2)) {
isInWord = true;
}
}
if(char1.equals(char2)) {
result += char2;
} else if(isInWord) {
result += "*";
} else {
result += "+";
}
}
}
}
public class 2015 Practive Exam FRQ {
public static void main(String[] args) {
HiddenWord word = new HiddenWord("HARPS");
System.out.println(word.getHint("HELLO"));
}
}