Computer Science Canada what is in.nextInt() ? |
Author: | javaster [ Fri Dec 14, 2007 6:39 pm ] |
Post subject: | what is in.nextInt() ? |
Hello Can anybody explain what in.nextInt() does? Thanks Javaster |
Author: | syntax_error [ Fri Dec 14, 2007 6:47 pm ] | ||
Post subject: | Re: what is in.nextInt() ? | ||
first of all you neeed to understantd that the "in" in your in.nextInt() is the name of the object
so the in.nextInt gets the next interager entered by the user and the "in" is teh object name of it |
Author: | Dan [ Fri Dec 14, 2007 7:23 pm ] |
Post subject: | RE:what is in.nextInt() ? |
Are you shure he means a Scanner? There are a few diffrent clases that could have that method including custom ones, user defined ones and i think RTP might even have some clases that have that method. |
Author: | syntax_error [ Fri Dec 14, 2007 7:37 pm ] |
Post subject: | Re: what is in.nextInt() ? |
Dan wrote: Are you shure he means a Scanner? There are a few diffrent clases that could have that method including custom ones, user defined ones and i think RTP might even have some clases that have that method. err ya i just assumed that he meant reading in the the next int and first thing i thought of was scanner class well to make sure javaster what is "in" pointing to? and what class or method are you talking about and if you don't know that and are you using RTP (ready to program)? sorry next time before posting a reply i will ask these things |
Author: | Tony [ Fri Dec 14, 2007 7:41 pm ] |
Post subject: | Re: RE:what is in.nextInt() ? |
Dan @ Fri Dec 14, 2007 7:23 pm wrote: i think RTP might even have some clases that have that method.
but this is "Java Help", not "RTP" ![]() I would have assumed it to be a Scanner... at the very least, it probably should be ![]() |
Author: | HeavenAgain [ Fri Dec 14, 2007 7:50 pm ] |
Post subject: | RE:what is in.nextInt() ? |
i have a feeling that i used this in.class before, inside it is bufferedreader for each datatype, and i think is a UoT prof who wrote this class. (before Scanner existed, before version 1.5?) but if you could upload the in.class, or even better the .java file, we could tell you exactly what it is ![]() |
Author: | javaster [ Sun Dec 16, 2007 7:26 pm ] | ||
Post subject: | Re: what is in.nextInt() ? | ||
syntax_error @ Fri Dec 14, 2007 6:47 pm wrote: first of all you neeed to understantd that
the "in" in your in.nextInt() is the name of the object
so the in.nextInt gets the next interager entered by the user and the "in" is teh object name of it Yes. You are right. Thanks. The guy was using Scanner, which I know nothing about - I always use BufferedReader and then use split and Integer.parseInt. Anyway, does .nextInt() only work with Ready to Program? |
Author: | syntax_error [ Sun Dec 16, 2007 7:39 pm ] |
Post subject: | Re: what is in.nextInt() ? |
no no .nextInt (); will work with any java complier but i do think you need a version 1.5 or higher not sure tho but as long as you create the object you can use the methods such as nextInt(); dont know if there is a way with creating the object tho... also if you don't know much bout the Scanner class use the API it works wonders |
Author: | Aziz [ Mon Dec 17, 2007 11:34 pm ] | ||
Post subject: | RE:what is in.nextInt() ? | ||
Scanner has been included since Java 5 (current version is 6). My teacher has us use a class called "in" to get input, and we call in.getInt(), but it's similar. To use Scanner, you have to pass it an input stream. It's handy to use for user input.
Does the dirty error handling work for you |
Author: | HeavenAgain [ Tue Dec 18, 2007 12:08 am ] |
Post subject: | RE:what is in.nextInt() ? |
yea, well if it is scanner, it doesnt make sense to put them in a class (again), since there is a scanner class, so the in.class must be bufferedreader!!!! so i am right!@@@@@@ ![]() |
Author: | Aziz [ Tue Dec 18, 2007 9:59 am ] |
Post subject: | RE:what is in.nextInt() ? |
in class could use a Scanner. Or a BufferedReader. It isn't a buffered reader though. BufferedReader does not have .next*() methods |
Author: | HeavenAgain [ Tue Dec 18, 2007 11:48 am ] | ||||
Post subject: | RE:what is in.nextInt() ? | ||||
you could overwrite anything inside a class, for example In.class
|
Author: | Aziz [ Tue Dec 18, 2007 2:13 pm ] |
Post subject: | RE:what is in.nextInt() ? |
![]() I said "could use a Scanner. Or a BufferedReader." You're previous post however said "the in.class must be bufferedreader!!!!". The verb "be" is a form of "is". "is" implies inheritance. That is why I said in isn't a bufferedreader. It could very well be, but the nextInt() method has nothing to do with that. Most likely "in" is a class named "in", and nextInt are static methods. (sort of like your example). |
Author: | HeavenAgain [ Tue Dec 18, 2007 3:31 pm ] |
Post subject: | RE:what is in.nextInt() ? |
oh :p i'm pretty bad at grammar :S but im like 99% sure is BufferedReader since there is no reason why someone would create another Scanner class and rename it In class. and Scanner is only available in version 1.5+, while bufferedreader is like 1.2+ But yes, it could be either one, it just makes more sense if it is bufferedreader ![]() so we are both right ![]() |
Author: | Euphoracle [ Wed Dec 19, 2007 3:48 pm ] |
Post subject: | RE:what is in.nextInt() ? |
It could also be a Random object, which returns a new random integer from min->max. |
Author: | Aziz [ Wed Dec 19, 2007 10:37 pm ] |
Post subject: | RE:what is in.nextInt() ? |
True. enough "coulds". Using static methods is easier for newbies to understand without having to learn how to create new objects. Of course I don't endorse the way of teaching ![]() |