1 2 3 Previous Next 30 Replies Latest reply: Jun 20, 2009 4:35 PM by jschellSomeoneStoleMyAlias Go to original post RSS
      • 15. Re: scanner -- how to count spaces a part of a string
        843789
        jschell wrote:
        I don't see that. You specifically said the following which is wrong and which the other poster corrected and then you disagreed with.

        "You cannot just use out.println() but rather System.out.println()."
        I never disagreed with the other poster who said you can achieve this by using imports. In my initial post, I stated the above, which you quoted me on and I stand by it. My statement is not incorrect. You can't use out.println() without using the import. This was my implication. I wasn't implying there was no possible way for him to use out.println() -- I was simply pointing out the OP did not include any imports and that he/she should include imports in his SSCCC for future posts if only for the convenience of the people on this board helping out. Yes, it was a just a simple case, and anyone who has programmed in Java for more than a few weeks would know which class needed to be imported -- This was really just advice for future posts (to include his imports). I'm not sure why this is being nit-picked as it really didn't have to do with the OP's problem.
        • 16. Re: scanner -- how to count spaces a part of a string
          jschellSomeoneStoleMyAlias
          ibanezplayer85 wrote:
          jschell wrote:
          I don't see that. You specifically said the following which is wrong and which the other poster corrected and then you disagreed with.

          "You cannot just use out.println() but rather System.out.println()."
          I never disagreed with the other poster who said you can achieve this by using imports.
          That might be what you meant, but it isn't how it reads. The work "cannot" is pretty explicit.
          In my initial post, I stated the above, which you quoted me on and I stand by it. My statement is not incorrect. You can't use out.println() without using the import. This was my implication.
          I wasn't implying there was no possible way for him to use out.println() -- I was simply pointing out the OP did not include any imports and that he/she should include imports in his SSCCC for future posts if only for the convenience of the people on this board helping out.
          Two people did not read it that way.
          Yes, it was a just a simple case, and anyone who has programmed in Java for more than a few weeks would know which class needed to be imported -- This was really just advice for future posts (to include his imports).
          I'm not sure why this is being nit-picked as it really didn't have to do with the OP's problem.
          Actually you are nit-picking. With the other posters first comment you could have explained that you meant something different rather than defending your incorrect statement.

          Your statement, as written, is wrong.
          • 17. Re: scanner -- how to count spaces a part of a string
            843789
            jschell wrote:
            ibanezplayer85 wrote:
            jschell wrote:
            I don't see that. You specifically said the following which is wrong and which the other poster corrected and then you disagreed with.

            "You cannot just use out.println() but rather System.out.println()."
            I never disagreed with the other poster who said you can achieve this by using imports.
            That might be what you meant, but it isn't how it reads. The work "cannot" is pretty explicit.
            Yes, however, my response was before the other poster's. I never said to the other poster that what he wrote was wrong (because obviously he isn't wrong). When I said that you cannot use out.println(), I meant that with the code sample the OP gave us, it would not compile. I still don't believe this to be incorrect. The OP didn't specify any imports, so the code does not compile as it is written. This is all I was saying.

            Ultimately, though, you are right, and I'd like to let the issue rest. I can see how what I wrote can be, and has been, misinterpreted. I apologize to both you as well as the OP for this. In the future, I will try to explain my comments in a way that's more clear and concise.

            Thanks
            • 18. Re: scanner -- how to count spaces a part of a string
              YoungWinston
              jschell wrote:
              I don't see that. You specifically said the following which is wrong and which the other poster corrected and then you disagreed with.
              "You cannot just use out.println() but rather System.out.println()."
              My two cents for the OP: use System.out.println().
              Yes, you have to write a bit more, but it saves confusions like this. Also, it's what most Java programmers would expect to see.

              Convention != slavish practice; but if you don't use them, be prepared to defend your decision.

              Winston
              • 19. Re: scanner -- how to count spaces a part of a string
                jschellSomeoneStoleMyAlias
                YoungWinston wrote:
                jschell wrote:
                I don't see that. You specifically said the following which is wrong and which the other poster corrected and then you disagreed with.
                "You cannot just use out.println() but rather System.out.println()."
                My two cents for the OP: use System.out.println().
                Yes, you have to write a bit more, but it saves confusions like this. Also, it's what most Java programmers would expect to see.

                Convention != slavish practice; but if you don't use them, be prepared to defend your decision.
                I would agree with that. I wouldn't use the shorthand import for anything.
                • 20. Re: scanner -- how to count spaces a part of a string
                  843789
                  I noticed this just now: I compile my program and got this result:
                  class PersonalInformation {
                  public static void main( String[] args ) {
                   
                            Scanner s = new Scanner(System.in );
                            
                            out.print("First name: ");
                            String firstName = s.nextLine();
                   
                            out.print("Last name: ");
                            String lastName = s.nextLine();
                            
                            out.print("Street Number: ");
                            String streetNumber = s.nextLine();
                       
                            out.print("Street: ");
                            String street = s.nextLine();
                  
                            out.print("Apt./Suite  - enter \"Apt.\" or \"Suite\" along with number (leave blank if not applicable): ");
                            String aptSuite = s.nextLine();
                   
                            out.print("City: ");
                            String city = s.nextLine();
                  
                            out.print("State: ");
                            String state = s.nextLine();
                             
                            out.print("Zip Code: ");
                            String zipcode = s.nextLine();
                       
                            out.println("\nYou entered:\n");
                            out.print(firstName + " " + lastName + "\n" + streetNumber + " " + street);
                             
                            if (!aptSuite.equals(" "))
                                 {out.print(", " + aptSuite + "\n" + city + ", " + state + " " + zipcode);}
                            else {out.println("\n" + city + ", " + state + " " + zipcode);}
                            
                            out.println();
                  
                            s.close();
                       }
                   
                  }          
                  
                  And this is the result when I entered some data:
                  
                  
                  
                  {code
                  First name: John
                  Last name: Smith
                  Street Number: 1234
                  Street: Any Street
                  Apt./Suite  - enter "Apt." or "Suite" along with number (leave blank if not applicable): 
                  City: Anytown
                  State: Any State
                  Zip Code: 12345
                  
                  You entered:
                  
                  John Smith
                  1234 Any Street, 
                  Anytown, Any State 12345
                  
                  }
                  What I'd like to know is -- in either case, whether I enter an apt number/suite or not, the prints a comman after the street name. and I can't figure out why. Can someone tell me what's wrong with my code? I can't see it.
                  • 21. Re: scanner -- how to count spaces a part of a string
                    800308
                    Did you so much as even read my previous posts in this thread? Please explain [ergo justify] why I should even bother reponding to someone who does not respond to me.

                    If what I posted previously was over your head then please just say so... I can "tone it down" a bit... I just thought a straitsfan (presumably not being twelve) would be ready to take a dip in the deep end of the pool.

                    To state my position crystal-clearly: I am annoyed that you chose not to respond AT ALL to my previous posts [which I self-evidently put a fair bit of effort into], even if I missed the mark... and therefore I am unwilling to help you AT ALL until you (a) do responsd to my previous posts, or at least (b) explain why you have not, and will not, do so.

                    Cheers. Keith.
                    • 22. Re: scanner -- how to count spaces a part of a string
                      843789
                      Dear corelttk:

                      I apologize -- I wasn't blowing you off. It's just that I haven't been here in a while, and I forgot about your post(s).

                      It was over my head, though -- I'm just starting out, and a lot of the terms and concepts I'm not familiar with. I wasn't sure how or what I was supposed to respond to. I'm not a professional programmer -- I'm doing this for the fun/intellectual exercise of it, reading and then going back to a little coding, which I may not get to after every read, and often times, I'm not able to get back to the forums.

                      I guess right now all I need to ask is why the comma keeps displaying. So again I apologize.

                      Just curious -- I don't quite get the reference between straitsfan and being ready to take a dip in the deep end of the pool.
                      • 23. Re: scanner -- how to count spaces a part of a string
                        800308
                        Straitsfan wrote:
                        Dear corelttk:

                        I apologize -- I wasn't blowing you off. It's just that I haven't been here in a while, and I forgot about your post(s).
                        No wuckers.
                        It was over my head, though -- I'm just starting out, and a lot of the terms and concepts I'm not familiar with. I wasn't sure how or what I was supposed to respond to. I'm not a professional programmer -- I'm doing this for the fun/intellectual exercise of it,
                        Good onya'... seriously... TV definately won't make you smarter.
                        reading and then going back to a little coding,
                        More coding!
                        which I may not get to after every read, and often times, I'm not able to get back to the forums.
                        OK, Like I said, forget my miffedness.
                        I guess right now all I need to ask is why the comma keeps displaying. So again I apologize.
                        I'll have a look at it for ya' ... watch this space...
                        Just curious -- I don't quite get the reference between straitsfan and being ready to take a dip in >>>> [the deep end of the pool|http://www.youtube.com/watch?v=3q7OPTxtR9w] <<<<
                        Actually, I was just thinking that a bloke who choses the nic "straitsfan" is likely to aged above twenty-five, and armed with the experience thereof, probably doesn't need or want "training-wheels" answers to his questions, even if those answers are a bit beyond his current capacities.

                        ... and I expect great things from anyone who programs just for the sheer fun of it, that's the quarter from which most of the really interesting ideas hail, and then it's upto "us experts" to bastardise those ideas to make them commercially viable... fun, fun, fun ;-) Ergo: "I think Java should do this" --> Two years later that's exactly what C# does ;-)

                        Cheers. Keith.
                        • 24. Re: scanner -- how to count spaces a part of a string
                          800308
                          Straitsfan wrote:
                          [Why does it always] print a comma after the street name?
                          What is the value of aptSuite? Use a debugger to find out, or a simple debug-print statement:
                          System.err.println("DEBUG: aptSuite='"+aptSuite+"'");
                          Cheers. Keith.
                          • 25. Re: scanner -- how to count spaces a part of a string
                            843789
                            I added your code and something strange happened, I don't know what I did, but I got an error message -- unfortunately I don't remember what it was, because I took it out and was trying to figure out how to use the debugger (never done it before -- there's a bit in the back of one of my books, and I'm reading it now.)

                            Just on a lark, I went and added your coding suggestion again just now, it it compiled and ran fine -- am I supposed to add it to a certain part of the program? because I placed it and the end of the code, just before the s.close statement and before my final out.println() statement. but it ran fine, and I still got the straying comma.

                            I'm going to have to read about the debugger and get back to you once I understand it -- but that may be a bit :-)

                            Thanks for your understanding. And, re: my nic, I am over twenty -five, and I'm guessing you are as well. I'm a guitar player by vocation, but unfortunately not by occupation -- wish I were (I'm currently looking for work after being laid off last September). I wouldn't have picked up the instrument if it weren't for Mark Knopfler -- after I heard 'Money for Nothing." I have three Stratocasters, including his signautre strat -- which I absolutely love. Fantastic guitar. I bought the first Dire Straits record and was hooked.

                            Judging from some of your vocabulary (especially the "Good on'ya") it sounds like your from Australia -- is that true? (I'm also a big fan of Crowded House and Neil Finn; not so much Split Enz, although I did buy a few of their songs from iTunes.) I met someone from there a few months ago, and he used the same expression. I know the Straits finished the Brothers In Arms tour in Sydney in '86 and I even think they did "Waltzing Matilda" towards the end. CH also finished their final concert at the foot of the Sydney Opera House as well.

                            Anyway, thanks again.

                            Edited by: Straitsfan on Jul 25, 2009 12:31 PM
                            • 26. Re: scanner -- how to count spaces a part of a string
                              800308
                              Yep, I'm an Ozzie. Guilty as charged... and yes indeed, I'm "just a bit" over 25.

                              My best mate has a strat... don't think he's picked it up for years, he prefers his gibson (acoustic)... but it still sits in his lounge-room, on it's own special stand, and it sure is purdy ;-)

                              Hmmm... Money for nothing... What a concept. Back when I was 15 or so, me and my best mate blew the tweeter out of his older brothers speaker (well, actually it "inverted", but you get what I mean) playing the start of Money For Nothing, cranked... You know, the first "full on" drum beat after the guitar lead in... yep that did it... Young Jeff (the brother) was NOT a happy boy when he arrived home. He was an AC/DC fan. ;-)

                              And one other thing... Can I suggest you lose the carpy books and start on a "real" one... something like TIJ or HFJ... or something else on [yawmarks list|http://forums.devshed.com/java-help-9/resources-for-learning-java-249225.html]... or indeed anything else... The dumbest thing about Everything For Dummies is (IMHO) the people who pay good money for them... and would you expect to learn to be chef in 21 days? Neurosurgeon? Vet? How about sculptor? Automechanic? Then why TF do people expect to be able to learn to write computer programmes at a professional level in 21 days or less? Is programming so simple and easy to learn? The evidence indicates otherwise.

                              Edit: Please see [Teach Yourself Programming in Ten Years|http://norvig.com/21-days.html] by Peter Norvig
                              package forums;
                              
                              import static java.lang.System.out;
                              import java.util.Scanner;
                              
                              class PersonalInformation 
                              {
                                private static final Scanner scanner = new Scanner(System.in);
                                public static void main( String[] args ) {
                              
                                  String firstName       = readString("First name     : ");
                                  String lastName        = readString("Last name      : ");
                              
                                  out.println("Apartment or Suite number. Eg: \"Apt. 96\" or \"Suite 2\", blank if N/A.");
                                  String apartmentNumber = readString("Apt./Suite     : ");
                              
                                  String streetNumber    = readString("Street Number  : ");
                                  String streetName      = readString("Street Name    : ");
                                  String city            = readString("City           : ");
                                  String state           = readString("State          : ");
                                  String zipcode         = readString("Zip Code       : ");
                              
                                  out.println();
                                  out.println("You entered:");
                                  out.println();
                                  out.println(firstName + " " + lastName);
                                  out.print(streetNumber + " " + streetName);
                                  if ( apartmentNumber.trim().length() > 0 ) {
                                    out.print(", " + apartmentNumber);
                                  }
                                  out.println();
                                  out.println(city + ", " + state + " " + zipcode);
                                  out.println();
                              
                                }
                              
                                private static String readString(String prompt) {
                                  out.print(prompt);
                                  return scanner.nextLine();
                                }
                              
                              }
                              
                              /*
                              First name     : Keith
                              Last name      : Corlett
                              Apartment or Suite number. Eg: "Apt. 96" or "Suite 2", blank if N/A.
                              Apt./Suite     : 1
                              Street Number  : 123
                              Street Name    : Nunnayabeezwax St
                              City           : Nowheresville
                              State          : QLD
                              Zip Code       : 4001
                              
                              You entered:
                              
                              Keith Corlett
                              123 Nunnayabeezwax St, 1
                              Nowheresville, QLD 4001
                              */
                              Cheers. Keith.

                              Edited by: corlettk on 26/07/2009 01:05
                              • 27. Re: scanner -- how to count spaces a part of a string
                                843789
                                Thanks for the advice.

                                I have to say like the dummies books, not because I expected to learn everything, but because it's an easy to understand, introductory book that makes the concepts in it easy to understand. Most of the other sources I come across aren't written that way, and it can be very frustrating, because they aren't written very well -- in general. It's a problem these days I think, that people in don't express their ideas clearly enough, and the result is that a lot of novices get turned off.

                                The other book I have -- Java in 21 days -- is more like that. I use the two books together, going back and forth to help clear up any questions I may have. But you say that TIJ or HFJ are pretty good, so I'll try one of those. Thanks again! :-)

                                Edited by: Straitsfan on Jul 25, 2009 1:37 PM
                                • 28. Re: scanner -- how to count spaces a part of a string
                                  800308
                                  Straitsfan wrote:
                                  Thanks for the advice.

                                  I have to say like the dummies books, not because I expected to learn everything, but because it's an easy to understand, introductory book that makes the concepts in it easy to understand. Most of the other sources I come across aren't written that way, and it can be very frustrating, because they aren't written very well -- in general. It's a problem these days I think, that people in don't express their ideas clearly enough, and the result is that a lot of novices get turned off.

                                  The other book I have -- Java in 21 days -- is more like that. I use the two books together, going back and forth to help clear up any questions I may have. But you say that TIJ or HFJ are pretty good, so I'll try one of those. Thanks again! :-)

                                  Edited by: Straitsfan on Jul 25, 2009 1:37 PM
                                  I conceed the point that the For Dummies series are more readable than a whole preceeding generation of "impenetrably dry" texts, but that readability comes at the cost of (IMHO) "completeness", leaving the student with massive gaps in there perception of the subject matter... and a little bit of knowledge is a dangerous thing... so IMHO the serious student must immediately progress to one (or more) of the "real" texts in order to skill-up to actually write useful computer programs... so what was the point of reading the For Dummies text? It's just a waste of time, IMHO ;-)

                                  BUT... If you find you need the "simple explanation" to get a leg-up on the basic concepts before you tackle "the complexities" then that's cool... I probably did the same thing in my time, except my "simple" text was called "The C Propgramming Language"... just please beware that Java for Dummies teaches Dummy Java Programming ;-)

                                  You're going to have to spit the Dummy eventually.

                                  Also worth noting that TIJ and HFJ are both every bit as "juicy" as FD and J21D, they're just more complete treatments of the same subject matter. The traditional "dry" style of computer texts has, thankfully, died a natural death.

                                  Cheers. Keith.
                                  • 29. Re: scanner -- how to count spaces a part of a string
                                    YoungWinston
                                    sarcasteak wrote:
                                    you can use out.println if you import it
                                    Aaaarggh! Please God no!

                                    Winston