有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

数组如何指向数组中的值并在java中对其使用方法

嘿,我有下面的代码,我想检查扫描项目的值是否与其中一个数组中的值相同,但是很难找到代码,有人知道吗?? 我真的在为整个数组编码而挣扎,我知道我的代码很长,但是如果你有什么想法,请告诉我。 请只发表建设性的评论,而不是那些对我有限的java知识做出评判的聪明人,因为我是java的初学者

   `package Library;
public class exercising 2 {
public static int id;

public exercising 2(){

    id=0;
    }
    public exercising 2(int _id){
        id=_id; 
  }
    public void set id(int _id){
        id = _id;
  }

    public int get id(){
    return id;
  }
}*`


 * package Library;
import java.util.Scanner;
import java.util.Arrays;
public class learning {
public static void main(String args[]){

 exercising 2 exercising 1 = new exercising 2();

Scanner Reader = new Scanner(System.in);
exercising 2[] exercise = new exercising 2[5];
exercise[0] = new exercising 2(12345);
exercise[1] = new exercising 2(678910);
exercise[2] = new exercising 2(1112131415);
exercise[3] = new exercising 2(1617181920);
exercise[4] = new exercising 2(2122232425);
System .out .print l n("write your id no");

int get Id = Reader . next Int();
boo lean can Loan= false;
int i = 0;
 if(get Id==exercise .hash Code()exercising 1.get id(){
System .out .print l n("you can't loan");;
}
else{
can Loan=false;
System .out. print l n("you're okay");
}
}
}*"

共 (1) 个答案

  1. # 1 楼答案

    Java中的名称必须是一个单词,由字母和数字组成(允许使用下划线,但不鼓励使用下划线)。没有空间。所以类应该被称为Exercising2,而不是exercising 2。类似地,您的方法应该被称为setIdgetId。由更多单词组成的名称通常以所谓的驼峰格书写,每个单词(第一个除外)都大写,以使新词的开头更清晰(现在没有空格)。当您想调用名为println的mwthod时,还需要在一个单词中键入名称,不带空格

    我假设代码中的反勾号、星号和双引号来自于对堆栈溢出的演示,而不存在于实际代码中。至少他们不应该这样

    现在我们正在讨论名称,约定说library带有一个小l,包名称是驼峰大小写规则的例外,它们根本没有任何大写字母。类名应该以大写字母开头,所以它是Exercising2(正如我已经提到的)和Learning。变量以小写字母开头,因此reader以小写字母r开头。当您只为自己编程时,您可能认为您不需要在意,但只要您希望其他人查看您的代码,例如在堆栈溢出上,如果您尝试遵守约定,您将得到更积极的响应

    PS这行出了点问题:

    if(get Id==exercise .hash Code()exercising 1.get id(){
    

    如果你告诉我们你的意图,也许有人能指导你