
-----------------------------------
javaster
Fri Dec 14, 2007 6:39 pm

what is in.nextInt()  ?
-----------------------------------
Hello

    Can anybody explain what in.nextInt() does?

  Thanks

Javaster

-----------------------------------
syntax_error
Fri Dec 14, 2007 6:47 pm

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 

import java.util.Scanner
public class {
bhal bhal
Scanner in = new Scanner (System.in)
int x;
System.out.println ("enter a number");
x=in.nextInt();
}


so the in.nextInt gets the next interager entered by the user
and the "in" is teh object name of it

-----------------------------------
Dan
Fri Dec 14, 2007 7:23 pm

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.

-----------------------------------
syntax_error
Fri Dec 14, 2007 7:37 pm

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.


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

-----------------------------------
Tony
Fri Dec 14, 2007 7:41 pm

Re: RE:what is in.nextInt()  ?
-----------------------------------
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 :lol:

-----------------------------------
HeavenAgain
Fri Dec 14, 2007 7:50 pm

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 :D

-----------------------------------
javaster
Sun Dec 16, 2007 7:26 pm

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 

import java.util.Scanner
public class {
bhal bhal
Scanner in = new Scanner (System.in)
int x;
System.out.println ("enter a number");
x=in.nextInt();
}


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?

-----------------------------------
syntax_error
Sun Dec 16, 2007 7:39 pm

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

-----------------------------------
Aziz
Mon Dec 17, 2007 11:34 pm

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.

Scanner in = new Scanner(System.in);

int i = in.nextInt();
double d = in.nextDouble();
String s = in.nextLine();

Does the dirty error handling work for you

-----------------------------------
HeavenAgain
Tue Dec 18, 2007 12:08 am

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!@@@@@@   :hb:  !!!!

-----------------------------------
Aziz
Tue Dec 18, 2007 9:59 am

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

-----------------------------------
HeavenAgain
Tue Dec 18, 2007 11:48 am

RE:what is in.nextInt()  ?
-----------------------------------
you could overwrite anything inside a class, for example
In.class
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class In
{
 static BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
  public static int nextInt()
  {
    try{
    return Integer.parseInt(input.readLine());
    }catch (Exception e){}
    return 0;
  }
// and so on, you could add more method, nextDouble, nextFloat, nextString etc...
}to tese this
class Test
{
  public static void main(Stringso BufferedReader does not need to have a .next*() method

-----------------------------------
Aziz
Tue Dec 18, 2007 2:13 pm

RE:what is in.nextInt()  ?
-----------------------------------
:| We're talking about the same thing

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).

-----------------------------------
HeavenAgain
Tue Dec 18, 2007 3:31 pm

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 :roll:
so we are both right :D yay

-----------------------------------
Euphoracle
Wed Dec 19, 2007 3:48 pm

RE:what is in.nextInt()  ?
-----------------------------------
It could also be a Random object, which returns a new random integer from min->max.

-----------------------------------
Aziz
Wed Dec 19, 2007 10:37 pm

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 :)
