Java – how to increase the loop by 10 instead of 1?

This is my current code: http://ideone.com/PfXNQc

import java.util.Scanner;

public class Temperature
{

    public static double convertFtoC(double F)
    {
        return (F-32)*5/9;
    }

    public static void main(String[] args)
    {
        double F; //Stores Farenheit
        double C; //Stores Celsius

        Scanner keyboard = new Scanner(system.in);

        System.out.print("Enter a temperature in Fahrenheit: "); //Enter in Farenheit
        F = keyboard.nextDouble(); //Stores Farenheit

        System.out.println("The temperature in Celsius is: " + convertFtoC(F)); //Displays Celsius (call convertFtoC(F) where celcuis conversion needed)

        F = 0;

        System.out.println("Fahrenheit\t Celsius"); 
        while (F <= 100)                    
        {
            // Display the F and C in increments of 10.
            System.out.println(F + "\t\t" + convertFtoC(F));
            // Increment for the next day.
            F++;
        }       
    }
}

I want the loop to be converted in increments of 10 instead of 1

Now it outputs this:

But I hope it is

Solution

What if you write the following?

while (F <= 90) //Last number before 100 is 90
{
        // Display the F and C in increments of 10.
        System.out.println(F + "\t\t" + convertFtoC(F));
        // Increment for the next day.
        F=F+10;
}

In addition, why do you use uppercase variables? Traditionally, you should start variable names with lowercase letters and object names with uppercase letters

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>