Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLucas Caldeira
977 PointsKeep getting this console error ! plese help !
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion
= '
'
at java.util.Formatter.checkText(Formatter.java:2579)
at java.util.Formatter.parse(Formatter.java:2565)
at java.util.Formatter.format(Formatter.java:2501)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at Prompter.displayProgress(Prompter.java:19)
at Hangman.main(Hangman.java:7)
Lucas Caldeira
977 Pointspublic Game(String answer) { mAnswer = answer; mHits = ""; mMisses = ""; }
public boolean applyGuess(char letter){ boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit){mHits += letter; System.out.println("You got it !!");}
else {mMisses += letter; System.out.println("Sorry you missed!!");}
return isHit;
}
public String getCurrentProgress(){
String progress = "";
for (char letter: mAnswer.toCharArray()){
char display = '-';
if (mHits.indexOf(letter) >= 0) {
display = letter;
}
progress += display;
}
return progress;
}
}
import java.io.Console;
public class Prompter { private Game mGame;
public Prompter(Game game) { mGame = game; }
public boolean promptForGuess() { Console console = System.console(); String guessAsString = console.readLine("Enter a letter: "); char guess = guessAsString.charAt(0); return mGame.applyGuess(guess); }
public void displayProgress() { System.out.printf("Whats the word? %\n", mGame.getCurrentProgress()); }
}
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.displayProgress();
boolean isHit = prompter.promptForGuess();
if (isHit){
System.out.println("We got a hit!");
}else {
System.out.println("You missed!");
}
prompter.displayProgress();
}
}
1 Answer
Victor Learned
6,976 PointsYou are incorrectly formatting the string with the following text:
Whats the word? %\n
%n and \n are 2 different ways of doing a newline. %n tells the formatter to put a newline in whatever format the platform requires whereas \n is a literal newline. With %\n you are escaping the newline char which is what's blowing up.
Victor Learned
6,976 PointsVictor Learned
6,976 PointsCan you post your code? Otherwise there is no way we can give advice.