Fórum ler temperatura fahrenheit e apresentala convertida em graus celsius #569485
10/12/2009
0
Jonas Morais
Curtir tópico
+ 0Posts
10/12/2009
Ricardo Staroski
public static double toCelsius(double f) {
return ( f - 32.0 ) * ( 5.0 / 9.0 );
}
Gostei + 0
10/12/2009
Jonas Morais
Gostei + 0
10/12/2009
Jonas Morais
1. import java.io.*;
2. import java.io.InputStreamReader;
3. public class temperaturaf {
4. public static void main (String args []) {
5. java.io.BufferedReader entrada;
6. System.out.println("Ler valor fahrenheit");
7. entrada = new java.io.BufferedReader (new InputStreamReader(System.in));
8. double c, f;
9. try {
10. float F = Float.parseFloat(entrada.readLine());
11. float C = (F -32.0) * ( 5.0 /9.0 );
12. System.out.println("Valor em Graus Celsius: " + C);
13. } catch (NumberFormatException e) {
14. System.err.println("Número digitado é inválido.");
15. } catch (IOException ex) {
16. System.err.println("Erro ao ler o valor digitado.");
17. }
18. }
19. } Gostei + 0
10/12/2009
Ricardo Staroski
if (c < 5) {
// imprima a mensagem "esta muito frio"
} else if (c <= 19) {
// imprima a mensagem "que frio"
} else {
// imprima a mensagem que falta...
}
Gostei + 0
11/12/2009
Jonas Morais
1. import java.io.*;
2. import java.io.InputStreamReader;
3. public class temperaturaf {
4. public static void main (String args []) {
5. java.io.BufferedReader entrada;
6. System.out.println("Ler valor Fahrenheit");
7. entrada = new java.io.BufferedReader (new InputStreamReader(System.in));
8. double c, f;
9. try {
10. float F = Float.parseFloat(entrada.readLine());
11. float C = (F -32.0) * ( 5.0 /9.0 );
12. System.out.println("Valor em Graus Celsius: " + C);
13. } catch (NumberFormatException e) {
14. System.err.println("Número digitado é inválido.");
15. } catch (IOException ex) {
16. System.err.println("Erro ao ler o valor digitado."); {
17. if (c < 5) {
18. System.out.println(" esta muito frio!");
19. else if (c <= 19) {
20. System.out.println(" que frio!");
21. else (c > 19){
22. System.out.println(" Esta muito quente !! ");
23. }
24. }
25. }
26. }
Gostei + 0
11/12/2009
Diogo Souza
import java.io.*;
import java.io.InputStreamReader;//você ja importou tudo de io ("*")!! Nao precisa disto...
public class TemperaturaF {//Nomes de classes iniciam com maiúscula!
public static void main (String args []) {
BufferedReader entrada;//se importou nao precisa repetir java.io!!
System.out.println("Ler valor Fahrenheit");
entrada = new BufferedReader (new InputStreamReader(System.in));
double c, f;//Você nao usa essas variaveis, portanto nao precisa delas.
try {
float F = Float.parseFloat(entrada.readLine());
float C = (F -32.0) * ( 5.0 /9.0 );
System.out.println("Valor em Graus Celsius: " + C);
} catch (NumberFormatException e) {
System.err.println("Número digitado é inválido.");
} catch (IOException ex) {
System.err.println("Erro ao ler o valor digitado.");
}
if (C < 5) {
System.out.println(" Está muito frio! ");
else if (C <= 19) {
System.out.println(" Que frio! ");
else {
System.out.println(" Está muito quente !! ");
}
}
}
Gostei + 0
11/12/2009
Carlos Heuberger
float C = (F -32.0) * ( 5.0 /9.0 );
float C = (F -32.0f) * ( 5.0f /9.0f );
float C = (float) ((F -32.0) * ( 5.0 /9.0 ));
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)