Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36104

Re: i need help figuring out what is wrong in my code

Newsgroups comp.lang.java.programmer
Date 2016-12-12 14:17 -0800
References (4 earlier) <o2mnbo$rqp$1@dont-email.me> <a7c79903-e047-4c1c-9d60-9260f41c3bed@googlegroups.com> <o2mqki$9c4$1@dont-email.me> <ceb2b427-1479-40ad-9796-ba7d646dfbc4@googlegroups.com> <o2n4ne$i5p$1@dont-email.me>
Message-ID <f23cdcf2-bcd5-4c3c-bb28-57a058d3861d@googlegroups.com> (permalink)
Subject Re: i need help figuring out what is wrong in my code
From Karim omar <karimyousrymohamedomar@gmail.com>

Show all headers | View raw


On Tuesday, December 13, 2016 at 12:28:49 AM UTC+3, Eric Sosman wrote:
> On 12/12/2016 3:28 PM, Karim omar wrote:
> > [...]
> > i totally got your point ,it`s because i am using nextInt() in the previous method instead of nextLine() and finInLine() is looking for a char in a string , ok i solved the issue by using finInLine() method before nextInt() call , but what if i still want the program to ask for age and get the int input then ask the yes or no question and get the char input ,how can i do it?
> 
>      Learn to read the Javadoc for the classes you use.  One of the
> good features of the language is that it has built-in mechanisms for
> documentation, and strongly encourages that the programmer use them.
> (One of the bad features is that the documentation is written by the
> programmers and not by professional writers!  This means you'll need
> to read the Javadoc with a lot of care, and be alert for small hints.)
> 
>      So, we turn to the Javadoc for Scanner and read about findInLine(),
> and we learn right away that there are two different methods of that
> name, one taking a String argument and the other a Pattern.  You're
> using the String one, and the Javadoc says it "behaves in exactly the
> same way" as the other one would with a Pattern derived from the String.
> Okay, fine, we can guess what's going on: The String version compiles
> its argument to a Pattern and calls the Pattern version.  (Or if it
> doesn't do exactly that, it does something equivalent.)
> 
>      So, we turn to the Javadoc for the Pattern-accepting version of
> findInLine(), and we read (emphasis mine)
> 
> 	"[...] If the pattern is found *before the next line separator,*
> 	the scanner [matches and returns it]."
> 
> and
> 
> 	"[...] If no such pattern is detected in the input *up to the
> 	next line separator,* then null is returned [...]"
> 
> In other words, findInLine() searches forward from the current position
> in the input, but *only within the current line;* it will not advance
> to the next line.  If you need to move to a subsequent line, you'll
> need to call some other Scanner method to get there; findInLine() won't
> do it unaided.
> 
>      Let's see: Does Scanner have a method that moves to the next line?
> We peruse the Javadoc for a while and we find a method that
> 
> 	"Advances this scanner past the current line and returns the
> 	input that was skipped. [...] The position is set to the
> 	beginning of the next line."
> 
> ... and Lo! it turns out to be a method you're already familiar with!
> Perhaps if you used that method before findInLine(), things might go
> more smoothly.  Care to try it?
> 
> -- 
> esosman@comcast-dot-net.invalid
> "Nobody ever went broke underestimating the intelligence of the
> American public." -- HLM (paraphrased)

damn!! , it`s (Scanner myNewScanner = new Scanner(System.in);) that solves it to reset the Scanner , couldn`t sleep before figuring it out , it appers that i am a little bit slow learner :)

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:13 -0800
  Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:15 -0800
    Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 11:27 -0500
  Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 08:54 -0800
    Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 12:02 -0500
      Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:06 -0800
        Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 12:40 -0500
          Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:52 -0800
            Re: i need help figuring out what is wrong in my code Eric Douglas <e.d.programmer@gmail.com> - 2016-12-12 10:21 -0800
            Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 13:36 -0500
              Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 12:28 -0800
                Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 16:28 -0500
                Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 13:39 -0800
                Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 14:17 -0800
                Re: i need help figuring out what is wrong in my code Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-12 18:08 -0500
      Re: i need help figuring out what is wrong in my code Karim omar <karimyousrymohamedomar@gmail.com> - 2016-12-12 09:09 -0800
  Re: i need help figuring out what is wrong in my code lewbloch@gmail.com - 2016-12-13 12:38 -0800
    Re: i need help figuring out what is wrong in my code Eric Douglas <e.d.programmer@gmail.com> - 2016-12-13 12:49 -0800
      Re: i need help figuring out what is wrong in my code lewbloch@gmail.com - 2016-12-14 17:01 -0800
        Re: i need help figuring out what is wrong in my code Martin Gregorie <martin@address-in-sig.invalid> - 2016-12-15 10:47 +0000
  Re: i need help figuring out what is wrong in my code Roedy Green <inquiry@mindprod.com> - 2016-12-13 16:07 -0800

csiph-web