I have to write a program for school that converts celsius to fahrenheit and vice versa using arguments. I have the following question:
Let's say the temperature is passed in arg[1]
, can I apply the conversation equation directly on arg[1]
like so ?
args[1] * 9 / 5 + 32
I tried it but I'm having an error about the *
operator saying "The operator * is undefined for the argument type. I also tried using "*"
instead.
Here's the unfinished code so far.
Please do not give me the final code itself as I want to learn instead of being given the answer
public class Temperature {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
System.out.println("Veuillez specifier c (celsius) ou f (fahrenheit) suivi de la température. Exemple argc arg32");
if (args[0].equals ("c"))
{
/*convertir en fahrenheit*/
int temperature = args[1] *9 /5 +32;
}
else if (args[0].equals ("f"))
{
/*convertir en celsius*/
}
}
}
You should be using b
. args[1]
is still a String, and that is why you are getting that error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With