How to convert a string to a double?
-
I need to convert the value of String-avg to the double-numberGrade. Thanks a lot for your help. import javax.swing.JOptionPane; public class April3 { public static void main(String [] args) { String avg; double numberGrade; char letterGrade; while ( ! avg.equals("-1") ) { avg = JOptionPane.showInputDialog("Please enter student average");; if ( (numberGrade >= 0.0) && (numberGrade <= 100.0) ) { letterGrade = getLetter(numberGrade); JOptionPane.showMessageDialog(null… letterGrade); } } } private static char getLetter(double n) { if (n >= 80) { return ('A'); } if (n >= 60) { return ('B'); } if (n >= 40) { return ('C'); } if (n >= 20) { return ('D'); } if (n >= 10) { return ('F'); } return ('Z'); } }
-
Answer:
You could just have getLetter return a String instead of a char, and put "A", "B" and so on instead of how they are now. Another choice is using Character.toString(), you need to import java.lang.Character for this. chars are just integer codes if I remember correctly.
Wayne at Yahoo! Answers Visit the source
Related Q & A:
- How to split a string in C++?Best solution by Stack Overflow
- How to replace a string inside of a Word Document?Best solution by Stack Overflow
- How to marshall a string in C?Best solution by Stack Overflow
- How to convert a video to a specific format?Best solution by Super User
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.