import java.util.*;
public class RandomTaxis
{
static int sum[] = new int[15];
public static void main(String[] args) throws Exception
{
RandomTaxis ran = new RandomTaxis();
System.out.print( "排序前 ");
ran.index();
System.out.println();
System.out.print( "排序后: ");
ran.bubbleTaxis();
ran.dimidiate();
}
public static void index()
{
for (int i = 0;i < sum.length ; i++ )
{
sum[i] = (int)(Math.random()*100);
System.out.print( " "+sum[i]);
}
}
public static void bubbleTaxis()
{
for (int i = 0;i < sum.length;i++ )
{
for (int j = i+1; j <sum.length ;j++)
{
if (sum[j] < sum[i])
{
sum[j] = sum[i];
sum[i] = sum[j];
}
}
System.out.print( " "+sum[i]);
}
}
public static int dimidiate()
{
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int start = 0;
int end = sum.length - 1;
while(start <= end)
{
int dem =(start+end)/2;//中间元素
if (sum[dem] == a )
return dem;
else if (sum[dem] > dem)
return end = dem - 1;
else
{
return start = dem + 1;
}
}
return -1;
}
}
我这个程序是想通过键盘来输入
一直输入
直到找到输入数字的索引
然后跳出输入流..
------解决方案--------------------
我这个程序是想通过键盘来输入
一直输入
直到找到输入数字的索引
然后跳出输入流..
------------------------------------------------
不是很懂 你的跳出条件
------解决方案--------------------
奇怪,JDK里面有Scanner这个类的,但是我怎么就不能引用呢?