floppyspace's Profile
Reputation: 25
Craftsman
- Group:
- Active Members
- Active Posts:
- 184 (0.15 per day)
- Joined:
- 04-February 10
- Profile Views:
- 2,094
- Last Active:
Apr 15 2013 06:45 AM- Currently:
- Offline
Previous Fields
- Country:
- AU
- OS Preference:
- Who Cares
- Favorite Browser:
- Chrome
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- PC
- Your Car:
- Ford
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Trimming and Parsing the input?
Posted 27 Mar 2013
Gungnir, on 27 March 2013 - 03:30 PM, said:Quote
you can not convert a double to a string
Yes, you can:
while((count < SIZE)){ System.out.print("Grade " + (++count) + ": "); gradesEntered = bf.readLine( ) ; if(gradesEntered.length() < 1){ System.out.println(String.valueOf(total)); break; } total = total + Double.parseDouble(gradesEntered); }
I was speaking to relation to it been used in this way....
gradesEntered = Double.parseDouble(bf.readLine( )) ;
-
In Topic: Trimming and Parsing the input?
Posted 27 Mar 2013
perhaps I should clarify what was meant by my post
grades entered has been used as a string
gradesEntered = Double.parseDouble(bf.readLine( )) ;
you can not convert a double to a string
if something similar to this is used
while((count < SIZE) && (exit == false)){ System.out.print("Grade " + (++count) + ": "); gradesEntered = bf.readLine( ) ; total = total + Double.parseDouble(gradesEntered); if(gradesEntered.length() < 1){ System.out.println(total); exit = true; }
it will throw an NumberFormatException-empty string (true the exception could be handled), if the user does not enter anything and just presses enter past an input line (which I interpret as how MissHaller wants to stop the program from running).
if(gradesEntered.length() < 1){ System.out.println(total); exit = true; } else { total = total + Double.parseDouble(gradesEntered); }
this will stop the error from showing up.
as for the while running once I am incorrect. -
In Topic: java assignment trying to find the surface area of the exterior
Posted 26 Mar 2013
-
In Topic: Trimming and Parsing the input?
Posted 26 Mar 2013
As Gungnir says,
But you will need to so something like
if(gradesEntered.length() < 1){ exit = true; } else { total = total + Double.parseDouble(gradesEntered); }
so you do not get an error when you parse the input and also note because it is a while loop it will always perform once so your output may not be as you desire but check it anyway.
gl -
In Topic: Loop to display asterisks
Posted 26 Mar 2013
as drakethedragon says it is one line
for(int k = 6; k >=1; k--)
needs to be changed to
for(int k = 0; k < j; k++)
My Information
- Member Title:
- D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Location:
- some page on the web
- Interests:
- Reading,Gardening,Computers,Cooking,Soccer,Anything tech.
- Years Programming:
- 2
- Programming Languages:
-
Learner of all languages.
Current main interest PHP,Java,Web Development
Anything and everything.
Contact Information
- E-mail:
- Click here to e-mail me
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
David W
07 Jun 2012 - 01:38floppyspace
12 Jan 2012 - 21:04Hello