Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助,不会写这个程序
czboycool





发贴: 2
积分: 0
于 2004-12-16 01:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
老外给的题目,不知道如何下手,谁能帮忙
Overview

Write a program named SearchTextA to search for a multiple occurrences of a string in a document provided by the DocumentA class (described in the section Document Object). The text to search for will be passed as a command line parameter. The program should output the text that will be searched for, and the line number and offset of each occurrence found. The output should follow strict format guidelines as described under Output below. A test case consisting of 3 files input.txt, output.txt, and search.txt should be submitted. The content of the files should should satisfy certain criteria as described under Test Case. A sample test case is shown under Sample Input/Output.

Document Object

The DocumentA.class is provided to you. Put the class file in the same directory as your source file when you compile. The DocumentA constructor requires a string representing a valid filename. The DocumentA class has 2 public methods: boolean hasNext() and String next(). hasNext() returns a boolean indicating if there are more lines of the file to be read. next() returns the next line of the file as a string without line termination. You should always call hasNext() before calling next().

Command Line Parameters

The program should accept two command line parameters. The first parameter should be a valid filename of the file to be searched. The second parameter will be the text to search for. Delimit this string with quotes (") if there are spaces or special characters in the string. If 2 parameters are not present, print out a message to System.err and return.

Program Logic

The program should create a DocumentA object using the filename passed as an argument. It should then retrieve lines of text from the document using the hasNext() and next() methods. Search each line retrieved for the search text. Different occurrences of the search text will not overlap. There might be several occurrences on one line. The occurrences may be adjacent to each other.

Output

Before searching begins, the program should output the string to be searched for on a line by itself to System.out using the following format: "Searching for 'string':", where string is the search text. For each match found in the document, the program should output an additional line with the following format: "Found at line n, position i", where n is the line number (starting from 1) and i is the character position (0 based). If no match is found in the document, print out "Not Found".




话题树型展开
人气 标题 作者 字数 发贴时间
3840 求助,不会写这个程序 czboycool 2554 2004-12-16 01:07

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923