Program1-1


package com.algo;

import java.util.Random;
import java.util.Scanner;

public class P1_1 {
static int N=20;
public static void main(String[] args){
int[] arr = new int[N];
int x,i;
int f = -1;

Random r = new Random();
for(i=0; i<N; i++){
arr[i]=r.nextInt(100);
}

System.out.println("随机生成的数据序列:");
for(i=0; i<N; i++){
System.out.print(arr[i]+" ");
}
System.out.println();
System.out.println();
System.out.println("输入要查找的整数:");
Scanner input = new Scanner(System.in);
x=input.nextInt();

for(i=0; i<N; i++){
if(x==arr[i]){
f=i;
break;
}
}
if(f<0){
System.out.println("没有找到数据:"+x);
}else{
System.out.println("数据:"+x+" 位于数组的第 "+(f+1)+" 个元素处\n");
}

}

}
/*
随机生成的数据序列:
64 35 61 51 83 11 4 35 7 34 90 34 32 98 95 53 66 9 90 72

输入要查找的整数:
11
数据:11 位于数组的第 6 个元素处
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值