-5

From input of a starting and ending fahrenheit temperature and a temperature increment, I want to construct a loop that calculates fahrenheit and temperature using the standard formulas and increments the conversion till it gets to the final fahrenheit.

A little of my code (the loop):

//For loop
 for(int i = 0; i<= endfarh; i++){
      Celsius = (double) (9.0/5.0) * (Tempincre + 32);
      Kelvin = (double) (Celsius + 273.15);

{

How would such a loop look like and what commands do I need?

  • 3
    and your question is? – Marcus Müller Sep 30 '17 at 17:23
  • what is the issue that you are facing? – Aman Chhabra Sep 30 '17 at 17:25
  • Your F -> C formula is wrong, by the way. – Joe C Sep 30 '17 at 17:28
  • 1
    Looking at your code the issue is as obvious as your attempt to carry out the task. You need to have a better understanding of how the [**for**](http://www.learnjavaonline.org/en/Loops) loop works. You've gathered the User input, now in your **for** statement initialization `(int i = startFarh; i <= endFarh; i+= farhIncrement)`. Now all you need to do is make sure you have the **proper** conversion formulas and write the results to console with: `System.out.print(...);` and or `System.out.println(...);` and or `System.out.printf(...);`. Google how to use each effectively. – DevilsHnd - 退職した Sep 30 '17 at 17:57

1 Answers1

0

Try something like this:

System.out.println( "Farenheit | Celsius  | Kelvin" );
// For loop
for ( double f = startfarh ; f <= endfarh ; f += 1d )
{
    double c = ( f - 32 ) / 1.8d;
    double k = c + 273.15;
    System.out.printf( "%7.2f°F = %6.2f°C = %6.2fK%n", f, c, k );
}
Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33