1

How to make that before plus Celsius values, was output plus sign, cons are automatically add to minus value. This is methods which calculate the value. Or maybe i need to use some output modification?

            public static double CtoF(double Celsius) {            
                System.out.println("Celsius |   Fahrenheit");
                System.out.println("");
                for (int i = 0; i <= 50; i++) {
                    Celsius = (Celsius*9/5)+32;
                    System.out.printf("%3d     |    ", i);
                    System.out.println((int) Celsius);
                }
                return Celsius;
            }

            public static double FtoC(double Fahrenheit) {            
                System.out.println("Fahrenheit |   Celsius");
                System.out.println("");
                for (int i = 0; i <= 50; i++) {
                    Fahrenheit = (Fahrenheit-32)*5/9;
                    System.out.printf("%3d       |    ", i);
                    System.out.println((int) Fahrenheit);
                }
                return Fahrenheit;
            }

Output of values:

Celsius |   Fahrenheit

  0     |    32
  1     |    89
  2     |    193
  3     |    379
  4     |    715
  5     |    1320
  6     |    2408
  7     |    4367
  8     |    7894
  9     |    14241
 10     |    25667

Fahrenheit |   Celsius

  0       |    -17
  1       |    -27
  2       |    -33
  3       |    -36
  4       |    -37
  5       |    -38
  6       |    -39
  7       |    -39
  8       |    -39
  9       |    -39
 10       |    -39

UPD: Here is answer: Format a number with leading sign

trigun117
  • 639
  • 7
  • 21
  • look at [enter link description here][1]https://stackoverflow.com/questions/5243316/format-a-number-with-leading-sign – Alexey K Oct 25 '17 at 16:36

1 Answers1

-2

You could get away with just a ternary operator inside of your printf statements.

System.out.printf( (Celsius > 0 ? "+" : "") + "%3d       |    ", i);
System.out.printf( (Farenheit > 0 ? "+" : "") + "%3d       |    ", i);

Here's a link: https://en.wikipedia.org/wiki/%3F:#Java

Jay Whaley
  • 24
  • 1
  • 1
  • 5