• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Double.parseDouble Troubles

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am doing an assignment for my Java class.
It asks to 1) Read input from a user. 2) convert the input to a double number if valid 3) find average.
I am trying to convert the String entered by user into a double number using Double.parseDouble.
 
Kara Wilimas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies, forgot to mention that these errors occur:

Grades.java:29: error: ')' expected
double count = Double.parseDouble(String sInput);
^
Grades.java:29: error: illegal start of expression
double count = Double.parseDouble(String sInput);
^
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already declared a variable named count in line 13. You can't declare another variable with the same name again in the same method, which is what you are doing in line 28 - you are declaring a new variable called count there.

Probably you just wanted to assign a value to the existing variable, instead of declaring a new variable. If that's what you wanted to do, then remove the type name double in line 28.
 
Kara Wilimas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thank you. I think I have it sorted now.
 
Marshal
Posts: 65425
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never use == false or == true. Not only are they poor style, but they are prone to your writing = by mistake in which case you might get two errors for the price of one.
Not b == false but !b
Not b == true but simply b
 
Campbell Ritchie
Marshal
Posts: 65425
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop using Double.parseDouble unless you are sure the text will be in the correct format for a double.
Find out about the methods of the Scanner class.
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!