Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: need help fast

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation need help fast

    Need help figure out a way using for loops or while loops to convert a string into astericks or question marks except not the white spaces.

    Example:

    I am going to sleep ==> * ** ***** ** *****

    then as the person guesses a letter and if they get it correct it gets added to the phrase

    Example:
    Guess a letter: g \\ user inputs g

    Output ==> * ** g***g ** *****

    need fast help please!


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help fast

    import java.util.Scanner;
    public class Exam01 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner stdIN = new Scanner(System.in);
    String secret;
    System.out.print("Enter The Secret Message: ");
    secret = stdIN.nextLine();
    for(String guess = ""; guess.length() < secret.length(); guess += '?')
    {
    System.out.print(guess);
    }


    }

    }

    this is where I'm at so far, but the output is way too many ?'s

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,537
    My Mood
    Grumpy
    Thanks
    0
    Thanked 166 Times in 157 Posts

    Default Re: need help fast

    You are printing out guess each time around the loop with out a new line. First loop prints 1 ?. Second loops prints out 2 ? now you see 3 ?. third loop prints 3 ? now you see 6 ? etc.
    Improving the world one idiot at a time!

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help fast

    yea idk if i'm just overlooking this problem, but my entire class seems to be having trouble with this "simple" task. I can't get the secret phrase to be displayed as a hidden message with ?'s. not only that I have no idea how to not print the spaces as question marks but as actual spaces. I'm getting frustrated and its not helping the situation lol.


    Sample run(s):
    Please enter the phrase to guess at : who do you love



    Common Phrase
    -------------
    ??? ?? ??? ????


    Enter a lowercase letter guess : f



    Common Phrase
    -------------
    ??? ?? ??? ????


    Enter a lowercase letter guess : o



    Common Phrase
    -------------
    ??o ?o ?o? ?o??


    Enter a lowercase letter guess : s



    Common Phrase
    -------------
    ??o ?o ?o? ?o??


    Enter a lowercase letter guess : w



    Common Phrase
    -------------
    w?o ?o ?o? ?o??


    Enter a lowercase letter guess : h



    Common Phrase
    -------------
    who ?o ?o? ?o??


    Enter a lowercase letter guess : d



    Common Phrase
    -------------
    who do ?o? ?o??


    Enter a lowercase letter guess : e



    Common Phrase
    -------------
    who do ?o? ?o?e


    Enter a lowercase letter guess : y



    Common Phrase
    -------------
    who do yo? ?o?e


    Enter a lowercase letter guess : u



    Common Phrase
    -------------
    who do you ?o?e


    Enter a lowercase letter guess : l



    Common Phrase
    -------------
    who do you lo?e


    Enter a lowercase letter guess : v



    Common Phrase
    -------------
    who do you love

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,537
    My Mood
    Grumpy
    Thanks
    0
    Thanked 166 Times in 157 Posts

    Default Re: need help fast

    Quote Originally Posted by Junky View Post
    You are printing out guess each time around the loop
    That is not what you want to do, is it? So what should you do instead.
    Improving the world one idiot at a time!

  6. #6
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help fast

    well I got it to print the correct number of characters by printing "?" instead of guess. but "?" is taking place of spaces, i tried to do an if statement where as if the charAt(i) wasn't between 'a' - 'z' then to do nothing, but it says i cant use the < operator to compare strings =_= . I'm too noob atm.

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help fast

    well i guess i'll just take a zero because i have absolutely no idea.

Similar Threads

  1. need help fast!!
    By nwollis in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 27th, 2010, 05:12 PM
  2. Externally sorting ints as fast as possible
    By Djikstrangle in forum Algorithms & Recursion
    Replies: 4
    Last Post: September 21st, 2010, 03:00 PM
  3. Code stopping, need help fast.
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 11th, 2010, 09:00 AM