(Java) 变量名称必须匹配模式?

huangapple go评论74阅读模式
英文:

(Java) Variable names must match pattern?

问题

import java.util.Scanner;

public class ComparingNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int FirstNum = Integer.valueOf(scanner.nextLine());
        int SecondNum = Integer.valueOf(scanner.nextLine());

        if (FirstNum > SecondNum) {
            System.out.println(FirstNum + " is greater than " + SecondNum + ".");
        } else if (FirstNum < SecondNum) {
            System.out.println(FirstNum + " is smaller than " + SecondNum + ".");
        } else {
            System.out.println(FirstNum + " is equal to " + SecondNum + ".");
        }
    }
}

Line 9: 变量名 'FirstNum' 必须匹配模式 '^[a-z][a-zA-Z0-9]$'。
Line 10: 变量名 'SecondNum' 必须匹配模式 '^[a-z][a-zA-Z0-9]
$'。

我的变量名有什么问题吗?作为一个初学者,简单的回答将会非常感激。

英文:
import java.util.Scanner;

public class ComparingNumbers {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int FirstNum = Integer.valueOf(scanner.nextLine());
        int SecondNum = Integer.valueOf(scanner.nextLine());

        if (FirstNum &gt; SecondNum) {

            System.out.println(FirstNum + &quot; is greater than &quot; + SecondNum + &quot;.&quot;);
        } else if (FirstNum &lt; SecondNum) {
            System.out.println(FirstNum + &quot; is smaller than &quot; + SecondNum + &quot;.&quot;);
        } else {
            System.out.println(FirstNum + &quot; is equal to &quot; + SecondNum + &quot;.&quot;);
        }
    }
}

Line 9: Name 'FirstNum' must match pattern '^[a-z][a-zA-Z0-9]$'.<br/>
Line 10: Name 'SecondNum' must match pattern '^[a-z][a-zA-Z0-9]
$'.

What is the issue with my variable names?. I am a beginner so a simple answer will be greatly appreciated.

答案1

得分: 1

Java变量名应采用驼峰式命名法。变量名应为firstNumsecondNum

英文:

Java variable names should be camelCase. Variable names should be firstNum and secondNum.

huangapple
  • 本文由 发表于 2020年10月5日 00:26:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64197109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定