• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

数组中查找元素

公共类FindOne {

公共静态void main(String[] args) {

int[] nums={3,93,62,34,29 };

int target=62

//遍历数组。如果你输入一个不存在的目标值,它将返回0,这将是不明确的。因此,使用不在数组中的负数代替下标来表示没有找到特定的值。

int result=-1;

for(int I=0;i nums.lengthi ) {

if (nums==622){

结果=I;

打破;

}

}

System.out.println(结果);

}

}

-1

进程结束,退出代码为0

导入Java . util . scanner;

公共类FindOne {

公共静态void main(String[] args) {

int[] nums={3,93,62,34,29 };

System.out.println('请输入数字:');

Scanner scanner=新扫描仪(system . in);

int target=scanner . nextint();

//遍历数组。如果你输入一个不存在的目标值,它将返回0,这将是不明确的。因此,使用不在数组中的负数代替下标来表示没有找到特定的值。

int result=-1;

for(int I=0;i nums.lengthi ) {

if (nums==target) {

结果=I;

打破;

}

}

if(result 0 | | result nums . length-1){

System.out.println('未找到身份证记录');

}否则{

System.out.println('身份证是:' nums[结果]);//nums[括号内为数组中特定值的位置号],整体表示数组中该位置的特定值。

}

}

}

请输入号码:

93

身份证是:93

进程结束,退出代码为0

Link to comment
Share on other sites