Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Ending the input with space.

    Hello, I've been learning java at school and am doing an assignment. Here is the question I'm having trouble with:

    "2. Write a program that reads a list of characters:
    eg. ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.
    inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character. Any other sequence should return an error message and a way of entering it correctly.

    Having read in the list (or during the reading of the list) the program is to find the longest continuous occurrence of consonants, outputting the vowels between which this occurs and the length of this string of consonants.

    {In the example above, the output would be 13 o u}
    Check for input errors and respond accordingly.
    "
    I have done most of it, the problem being that I don't know how to end the scan with a space so that I don't have to press enter. I have done the bit that finds the biggest amount of consonants in a row. Could someone point me in the right direction? (I'm writing in netbeans)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Ending the input with space.

    how to end the scan with a space so that I don't have to press enter
    I'm not sure what you are asking. If the user is entering data via the keyboard, the program will not get to respond to it until Enter is pressed.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Ending the input with space.

    Perhaps you could help me understand the first part of the question regarding the input:
    Write a program that reads a list of characters:
    eg. ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.
    inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character. Any other sequence should return an error message and a way of entering it correctly.
    What do I have to do with the input? I don't really understand what this bit means.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: Ending the input with space.

    Doesn't make much sense unless this is some GUI-based application (eg Swing).
    If it's a console app, then nothing is sent to the app by (for example) a windows console until the <Enter> key is hit.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Ending the input with space.

    That's what I'm thinking, but we haven't done Swing or Jframe in class at all, not even the mention of it.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Ending the input with space.

    If nothing is sent to the program until the user presses: Enter, what does that mean for the way the program specifications are written?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Ending the input with space.

    Hmm.. I'm not sure. I'm quite new to this, so you'll have to make it sort of obvious to me. But I'm also trying to do as much as possible by myself.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,731
    Blog Entries
    7
    Rep Power
    21

    Default Re: Ending the input with space.

    Quote Originally Posted by shufflermuffler View Post
    You do not press enter after each character.
    That doesn't forbid you to press <enter> at the end of the line; you can simply read the entire line and do your job ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: Ending the input with space.

    You bring up an interesting point. I never thought about it from a Java perspective but as I recall on Unix using C you could programmatically set "stty raw". I guess Java IO doesn't offer anything similar for console IO.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Ending the input with space.

    Quote Originally Posted by shufflermuffler View Post
    2. Write a program that reads a list of characters:
    eg. ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.
    inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character.
    I've noted that it states, "reads a list of characters" (and not "reads a character at a time.") "You do not press enter after each character" may be saying that you can type in all the letters, and after the final space character, only then you can press Enter. Enter is not pressed "after each character" as it is pressed only after the final character. I'm kind of stretching the interpretation of the assignment, so best get this clarified with your teacher.

Similar Threads

  1. Need help ending a loop
    By Zeronitic in forum New To Java
    Replies: 5
    Last Post: 01-27-2012, 02:25 AM
  2. Space Warrior - Multiplayer Space Shooter
    By stes in forum Reviews / Advertising
    Replies: 2
    Last Post: 01-11-2012, 09:19 AM
  3. ending a csv
    By paul1024 in forum New To Java
    Replies: 2
    Last Post: 05-04-2011, 03:14 AM
  4. ending a graphics class
    By imorio in forum AWT / Swing
    Replies: 11
    Last Post: 08-16-2010, 06:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •