Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 what is in.nextInt() ?
Index -> Programming, Java -> Java Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
javaster




PostPosted: Fri Dec 14, 2007 6:39 pm   Post subject: what is in.nextInt() ?

Hello

Can anybody explain what in.nextInt() does?

Thanks

Javaster
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: 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
Java:

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




PostPosted: 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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
syntax_error




PostPosted: 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
Tony




PostPosted: 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" Wink

I would have assumed it to be a Scanner... at the very least, it probably should be Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
HeavenAgain




PostPosted: 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 Very Happy
javaster




PostPosted: 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
Java:

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




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Aziz




PostPosted: 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.

code:
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




PostPosted: 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!@@@@@@ Head Bang !!!!
Aziz




PostPosted: 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
HeavenAgain




PostPosted: 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
Java:
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
Java:
class Test
{
  public static void main(String[] args)
  {
    System.out.println(In.nextInt());
  }
}
so BufferedReader does not need to have a .next*() method
Aziz




PostPosted: Tue Dec 18, 2007 2:13 pm   Post subject: RE:what is in.nextInt() ?

Neutral 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




PostPosted: 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 Rolling Eyes
so we are both right Very Happy yay
Euphoracle




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: