can anyone help with this program I tried to get user input but everytime I change the celcius to double or move it I get an error code that says it may not have been initilized. thanks for any help.

import java.util.Scanner;

	 class conversion{
	 	public static void main(String args[]){
	 		Scanner tempature = new Scanner(System.in);
	 		float DegreesFahrenheit, DegreesCelcius;
	 		DegreesFahrenheit= (DegreesCelcius+32)*9/5;


Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

6 Years
Discussion Span
Last Post by Tarkenfire

Edit: As for the not initialized problem, when you create the Celsius, be sure to initilize it when you declare it, ala this:

float celsius = 0.0;
Double celsius2 = 0.0;
int celsius3 = 0;

That SHOULD fix your IDE giving that "may not be initialized" error.

As for the program in general, you're not quite using the scanner class right.

Okay, the easiest explanation I can do without just showing source code (which I WILL do) is that you need to use the scanner class to assign values to variables, they won't work inside of println() methods, perhaps this example will demonstrate what I mean:

import java.util.Scanner;

public class Main 
    public static void main(String[] args)
        /*The basic problem is that the scanner class needs to be used to "catch"
         * input and reference a variable to it.
        Scanner keyIn = new Scanner(System.in);
        double tempC;

        //you only need to use System.out.println() to do output, not input.
        System.out.println("Enter temp in Celsius");
        tempC = keyIn.nextDouble(); // Or .nextLine, .nextInt, .next

        System.out.println(tempC + " degrees Celsius is " + ((9/5) * tempC + 32) +
                            " degrees Fahrenheit.");


Edited by Tarkenfire: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.