This question already has answers here:
Variables might not have been initialized
                                
                                    (3个答案)
                                
                        
                5年前关闭。
            
        

它一直说可变英里可能尚未初始化?
这是问题所在:

浮动公里=英里* 1.609f;

这是完整的代码:

import java.io.*;


public class MilesToKilometres
{

   public static void main(String[] args)throws Exception

   {

 //1 mile = 1.609 kilometre;

       int miles;
       System.out.print("17");
       float km = miles * 1.609f;
       System.out.println(miles + " miles is " + km + " kilometres. ");
    }
}

最佳答案

给英里一个默认值。改变这个

int miles;




int miles = 0;


要么

int miles = 17;  //<-- Since you print "17" on the next line.

10-06 13:36