• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol parseInt

 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hey guys,
when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the JDK version that you are using.
 
Winston Gutkowski
Bartender
Pie
Posts: 10509
64
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java folder there is jdk1.6.0_18 and jre6 and jre7
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston


in the java documentation i have, it says:
it is a static public memeber of Integer class
parseInt(String s)
Parses the string argument as a signed decimal integer.
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.


oh i get it... in java, a string array contains references to the string objects and not the strings themselves so i shud use args[0]??let me try it
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:
Winston Gutkowski wrote:
thejwal pavithran wrote:when i compile the above program, i get the error that Cannot find symbol method parseInt()..please help me..

What type is 'args', and what type does Integer.parseInt() take as its parameter?

Winston


in the java documentation i have, it says:
it is a static public memeber of Integer class
parseInt(String s)
Parses the string argument as a signed decimal integer.


But you're not passing it a String. Hence the error.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:
Ashwin Sridhar wrote:You are trying to pass a array as parameter to Integer.parseInt(), but you should actually pass a String Object.


oh i get it... in java, a string array contains references to the string objects and not the strings themselves


No variable ever contains an object in Java. Array variables are not special in that sense. A variable contains a primitive, a reference, or null. A String variable contains a reference to a String object. A String[] variable contains a reference to a String[] object, which in turn contains references to String objects.

so i shud use args[0]??let me try it


If you want to parse the first arg that was passed, yes.
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so how wud i read ints during run time? like scanf or cin?
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have your numbers passed in as a part of arguements in command line. But it would be passed as String and you could convert it into int as you do.

Assume you call your testClass.java and pass 10 as input in command line.

you will do a ,

This 10 would be passed as a String and would be first element in the array args.

So, you convert into int as ,

Remember if you pass anything other than int and try to convert, you will get a NumberFormatException.
 
Winston Gutkowski
Bartender
Pie
Posts: 10509
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:so how wud i read ints during run time? like scanf or cin?

First: Please UseRealWords (←click). This isn't an SMS message.

Second: There's nothing to stop you from piping input to a Java program. On the other hand, things like scanf() are methods, not programs; and cin is a stream, and it's equivalent in Java is System.in.

Winston
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:You could have your numbers passed in as a part of arguements in command line. But it would be passed as String and you could convert it into int as you do.



Sir if i want to write like

System.out.println("PLEASE ENTER YOUR NUMBER ");

Then how will I read the value entered by user into an int variable?i am looking for something like cin or scanf
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should use System.in . Look this doc
 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Sridhar wrote:Then you should use System.in . Look this doc


thank you.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:Then how will I read the value entered by user into an int variable?i am looking for something like cin or scanf

Class java.util.Scanner would be good for that. Look at the API documentation for that class - it has an example for exactly what you want to do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic