Creation of a Fahrenheit to Celsius degree conversion table

2
Write a program that gives two temperatures in degrees Fahrenheit (integer values) produces a table with all values in that interval half a degree Fahrenheit. For example, running the program for values 30 and 35 should produce the following output :

Specify range values separated by space (min max):

30

35

Fahrenheit Celsius

30.00 -1.11

30.50 -0.83

31.00 -0.56

31.50 -0.28

32.00 0.00

32.50 0.28

33.00 0.56

33.50 0.83

34.00 1.11

34.50 1.39

35.00 1.67

And I leave my code there, I do not know if they can understand the reasoning I tried to have but it's also complicated because I still have a lot of doubts about using the for loop. When I try to run this code, the program asks for the maximum and minimum values, but after I enter the maximum the program gives the error:

  

java.util.IllegalFormatConversionException: f! = java.lang.String

public static void main(String[] args)
{
    System . out . println("Por favor indique um valor minimo:");
    int min = scanner.nextInt();
    System.out.println("Agora indique um valor máximo:");
    int max = scanner.nextInt();
    double celsius = (min-32*(5/9));
    int i = 0;
    min++;


    for (i=0; max + 1 > min;min++)
    {
        System.out.printf("%6.2f\t\t%6.2f\n","Fahrenheit" + min + " Celsius " + celsius);
    }
}
    
asked by anonymous 28.10.2017 / 13:23

1 answer

3

There are several errors, some of them maybe because some of the code is missing.

If you are going to calculate data with a decimal part you need to use at least float , it can not be an integer.

If the calculation needs to be done in each row of the table the calculation formula must be inside the loop to repeat each time.

And it should do with the variable of the loop that is increasing. Alias who should increment is the control variable of the loop and not the minimum. The minimum must be used to initialize it. The increment must be 0.5 as shown in the statement. The output condition was also wrong, the control variable should go to the maximum.

Text formatting is also wrong. See documentation how to use.

import java.util.*;

class Ideone {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in); 
        System.out.println("Por favor indique um valor minimo:");
        float min = scanner.nextFloat();
        System.out.println("Agora indique um valor máximo:");
        float max = scanner.nextFloat();
        System.out.printf("Fahrenheit Celsius\n");
        for (float i = min; i <= max; i += .5) {
            System.out.printf("%6.2f     %6.2f%n", i, ((i - 32.0) * ( 5.0 / 9.0)));
        }
    }
}

See running on ideone . And no Coding Ground . Also I placed in GitHub for future reference .

    
28.10.2017 / 13:51