Can I use an argument in an equation

I need to write a program for a school that converts a Fahrenheit target and vice versa using arguments. I have the following question:

Say the temperature is passed in arg[1], is it possible to apply the conversation equation directly to arg[1]so?

args[1] * 9 / 5 + 32

I tried, but I have an error about the statement *saying: "The * operator is undefined for the type of the argument. I also tried using it "*"instead.

Here is the incomplete code.

Please do not give me the latest code myself, as I want to study, instead of an 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*/
        }
    }
}
+4
source share
3 answers

b. args[1] - , .

+5

, , , :

public static void main(String[] args) {
    int[] foo = {2, 4, 6};
    System.out.println(foo[0] * foo[1]); // prints 8
}

, args - String[] ( " " ), ( Java, ). int, , .

+3

-

:

Because these arguments are passed through the command line, they are known as command line arguments. The passed String arguments are stored in the array specified in the main () declaration. args [] is now a three-dimensional array of String. Access to these elements is the same as the elements of a regular array. The following is a complete add program that can add any number of integers passed as command line arguments.

public class Add {

    public static void main(String[] args) {
        int sum = 0;
        for (int i = 0; i < args.length; i++) {
           sum = sum + Integer.parseInt(args[i]);
        }
        System.out.println("The sum of the arguments passed is " + sum);
    }
}

And now you can complete your code

Happy coding :)

0
source

Source: https://habr.com/ru/post/1540448/


All Articles