a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 134|回复: 0

[考试试题] 2012JAVA模拟试题及答案:编程题30

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
【程序30】      u; q9 d. t- p2 H
题目:有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。     
% }+ r9 E8 _' B/ W. h//此程序不好,没有使用折半查找插入
2 Y5 ~, W* G7 C5 m8 t+ K+ I! `import java.util.*; 7 _# g% S5 }7 M* o
public class lianxi30 {
4 Q0 l# E- S/ Q5 u$ M, s, I% O* t3 epublic static void main(String[] args) { 9 h  N+ Y- s: ^* G* m3 f& H: T& f& v
   int[] a = new int[]{1, 2, 6, 14, 25, 36, 37,55}; / l+ M3 G! i$ K" v! B
   int[] b = new int[a.length+1];
. w: x) b) ^1 d( f   int t1 =0, t2 = 0;                                            
! o" ~! m6 D4 ~. b   int i =0; 2 w" L) r2 `7 {
   Scanner s= new Scanner(System.in); 2 V  n, f/ R: J  R
   System.out.print("请输入一个整数:"); 9 W( R' m4 y+ o. ~; Z+ Y
   int num = s.nextInt();
+ X, F( j$ ?: L# {1 D; X( g, ]   if(num >= a[a.length-1]) { + {1 O' |8 v3 J: V0 P
    b[b.length-1] = num;   @0 v7 K" L% I  x- [6 i: H/ I
    for(i=0; i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-5 21:13 , Processed in 0.223651 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表