查找导入的变量来自何处

时间:2013-03-10 05:16:37

标签: java string

我正在学习Java类并有以下示例来帮助我使我的代码运行良好,但我无法运行我的代码。我发现问题在于strAlt然而我无法告诉strAlt在以下代码中的定义。使用Net beans中的调试器,我发现当它首次用于交换机测试时,strAlt被定义为字符串“03”,它被转换为整数3,但我不确定字符串03的来源。< / p>

public class NWSFB
{
   /** A class variable containing the Station Weather */
   private String strWea ;
   /** The Constructor */
   public NWSFB(String strVar)
   {
      // this is the constructor
       strWea = strVar;
   }


public String getWindInfo(String strAlt)
{
   String strRet;
   strRet = "The wind direction for " + strAlt + "000 feet is " + getWindDir(strAlt);
   return strRet;
}
/**
This routine will accept a string containing the altitude
and will return the starting position of the altitude weather
as an integer.
@param strAlt A string containing the altitude
@return An integer showing the position of the altitude weather within the station weather              
*/
private int getPos(String strAlt)
{
   int intAlt;
   int intRet =0;
   intAlt = Integer.parseInt(strAlt);
   switch (intAlt)
   {
     case 3:
      intRet = 4;
      break;
     case 6:
      intRet = 9;
      break;
     case 9:
      intRet = 14;
     // etc .... you can figure out the the other altitudes
   }
   return intRet;
}
 public String getAltitudeWeather(String strAlt)
 {
   // get the position in the station weather string
   int intPos = getPos(strAlt);

   // strAltitudeWeather contains a seven character string 
   String strRet = strWea.substring(intPos,intPos+7);

   // return the result
   return strRet;
 }
public String getWindDir(String strAlt)
 {
   String strRet = getAltitudeWeather(strAlt);
   return strRet.substring(0,2);
 }
}

此类用于运行类天气,如下所示

// this code will be saved in a file called Weather.java
public class weather
{
   public static void main(String[] args)
    {
      // the next line is very long and ends with 352853
        //This code doesn't really end in 352853 I think when it did it was getting   diffrent weather data
     final String FAA_FD="SAN 3106 2915+23 2714+16 0710+08 1010-07 1916-17 222331 213141 203753";
     System.out.println("Start of Program Weather") ;
     NWSFB windsAloft = new NWSFB(FAA_FD);
     System.out.println(windsAloft.getWindInfo("03"));
     System.out.println(windsAloft.getWindInfo("06"));
     System.out.println(windsAloft.getWindInfo("09"));
     System.out.println(windsAloft.getWindInfo("12"));
     // etc. for the other altitudes
     System.out.println("End of Program Weather") ;
  }
}

1 个答案:

答案 0 :(得分:2)

这是字符串的来源。

System.out.println(windsAloft.getWindInfo("03"));
System.out.println(windsAloft.getWindInfo("06"));
System.out.println(windsAloft.getWindInfo("09"));
System.out.println(windsAloft.getWindInfo("12"));

字符串通过NWSFB进入getWindInfo()课程。 从那里传递给getWindDir()getAltitudeWeather() 最后到getPos()