Java - 否则如果没有if?

Red*_*ddy -5 java comments if-statement

嘿,所以我在添加注释之前使用了这个Java程序,但是现在我收到了一个错误,其中if和else语句说他们没有if,这些注释是否干扰了如何读取if语句?任何帮助深表感谢.

/**
  * A class that takes 2 different times in military time as input and 
  * outputs the difference in hours and minutes.
  *
  * @author Name
  */
import java.util.Scanner;
public class Assignment1Q3
{
    public static void main(String[] args) 
    { 
    Scanner in = new Scanner(System.in);
    System.out.print("Please enter the first time: ");
    int fTime = in.nextInt();
    System.out.print("Please enter the second time: ");
    int lTime = in.nextInt();
    int tDifference = Math.abs(fTime - lTime);//Calculates the absolute difference.
    String strTDiff = String.valueOf(tDifference);//Converts the value to a String.
    int length = strTDiff.length();//Obtains the length of the value.
    String hours = "";//Declares the values to be initialized in the if statement.
    String minutes = "";
    if (length == 4)
    {
        hours = strTDiff.substring(0, 2);/**If the number of digits is 4, the first
        minutes = strTDiff.substring(2, 4);*two are the hour.
     }                                      */
    else if (length == 3)
    {
        hours = strTDiff.substring(0, 1);/**If the number of digits is 3, the first
        minutes = strTDiff.substring(1, 3);*one is the hour.
    }                                      */
    else
    {
        hours = ("0");                   /**If the number of digits is not 4 or  3,
        minutes = strTDiff.substring(0, 1);*the value is less than 1 hour.
    }                                      */
    System.out.println(hours + " hours " + minutes + " minutes");
    }
}
Run Code Online (Sandbox Code Playgroud)

Den*_*ret 9

那是因为}在你的最后一次else评论之间/*和之间*/.

任何正确的代码编辑器的颜色都应该明确,就像在问题中一样.