标题:[原创]求助:大家给我看看这个程序,谢谢!
取消只看楼主
magic475
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2005-1-14
 问题点数:0 回复次数:1 
[原创]求助:大家给我看看这个程序,谢谢!
//使用顺序查找法查找数组中的元素

import *;

import java.applet.Applet;



public class FindSort

{

    public static void main(String[] args) throws IOException

    {

        BufferedInputStream in = new BufferedInputStream(System.in);

        BufferedOutputStream out = new BufferedOutputStream(System.out);

        int y[] = { 2, 4, 5, 7, 9, 0};

        int a;

        byte b[] = new byte[2];

        System.out.println("请输入要查询的数字: ");

        a = in.read(b, 0, 2);

        boolean findOut = false;

        for(int i = 0; i < 6; i++)

        {

            if(y[i] == a)

            {

                findOut = true;

                break;

            }

        }

        if(findOut == false)

        {

            out.write(b, 0, 1);

            System.out.println("没有找到!");

            out.flush();

        }

        else

            System.out.println("找到!");

    }

};

/*----问题:无论我输入什么,结果总是显示为“找到”,请问这个是什么问题,谢谢各位了!---*/

2005-08-28 21:17
magic475
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2005-1-14
得分:0 
谢谢J湖散人!初学JAVA,根本不知道read(byte[] byte, int offset, int len)这个方法的使用。这个例子是引自科学出版社的《精通JAVA 2 》第96页,运行以后发觉不对,所以就来发帖了。
还望各位能够帮忙修改下这个程序,万分感激!
2005-08-29 00:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-26206-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.834011 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved