Hi,
Please see my following code. At line 9, I am accepting user input, but I want to convert into float for calculation at line 11. How to do that ? I tried to repalce "String f" to "float f" at line 9, but it is giving error.
------------------------------------------------------------
package myprojects.temperature;
import java.io.*;
1 class Temperature
2 {
3 public static void main(String args[]) throws IOException
4 {
5 BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
6 System.out.println("This program converts Temperature in Fahrenheit to Celsius"
7 System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
8 System.out.println("Enter temperature in fahrenheit:"
9 String f = myIn.readLine();
10 // Calculation
11 float c = (f - 32) / 1.8;
12 // Display Result
13 System.out.println("Temparature in Celsius: " + c);
14 }
15 }
-------------------------------------- There is always a new solution for the same problem.
Anonymous
Please see my following code. At line 9, I am accepting user input, but I want to convert into float for calculation at line 11. How to do that ? I tried to repalce "String f" to "float f" at line 9, but it is giving error.
------------------------------------------------------------
package myprojects.temperature;
import java.io.*;
1 class Temperature
2 {
3 public static void main(String args[]) throws IOException
4 {
5 BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
6 System.out.println("This program converts Temperature in Fahrenheit to Celsius"
7 System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
8 System.out.println("Enter temperature in fahrenheit:"
9 String f = myIn.readLine();
10 // Calculation
11 float c = (f - 32) / 1.8;
12 // Display Result
13 System.out.println("Temparature in Celsius: " + c);
14 }
15 }
-------------------------------------- There is always a new solution for the same problem.
Anonymous