Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use an argument in an equation

Tags:

java

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*/
        }
    }
}
like image 969
Cherry Avatar asked Feb 13 '23 23:02

Cherry


1 Answers

You should be using b. args[1] is still a String, and that is why you are getting that error.

like image 110
Natecat Avatar answered Feb 15 '23 12:02

Natecat