• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Cannot find symbol parseInt

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the JDK version that you are using.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in java folder there is jdk1.6.0_18 and jre6 and jre7
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so how wud i read ints during run time? like scanf or cin?
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you should use System.in . Look this doc
 
sinatra roger
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ashwin Sridhar wrote:Then you should use System.in . Look this doc



thank you.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can't .... do .... plaid .... So I did this tiny ad instead:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic