Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help!problem

Status
Not open for further replies.

poland

Technical User
Feb 11, 2002
3
JP
I just started to study Java and already have a problem .We need to write a program that reads the file name as COMMAND LINE ARGUMENT and then opens and processes file.The file will contain lines of colon separated integers,n per line .To process the file the code will determine and display the following :
The average integer value og each line
The max integer value of each line
The min integer value of each line
Tha average integer value fot the entire value
the min -||-
the max -||-

can anyone help me,please ?i don't know how to start
 
Ok - sounds like an assignment - so I won't give you the complete answers as that won't help you any in the long run. What you have to do is all straight foward stuff - so I'll just give you some hints to point you in the right direction w/ the right resources (probably not the exact answer you want - but I'm not going to do your assignment for you :) )

Hints
[1] your class will need a method :
public static void main(String[] args)
{
//your code
}}

to run and accept command line args. The command line args are passed in a String[] array (args). So the first one will be in arg[0].



[2] Read the online Java tutorial dor IO from Sun :
This will teach you how to open and read files using FileStreams.

[3] Consult the J2SE javadocs on the following classes
java.io.File
java.io.FileReader

[4] For parsing each line checkout the J2SE javadocs on the following classes
java.util.StringTokenizer

[4] For the arthitmetic on each line checkout the J2SE javadocs on the following class
java.lang.Math


Over to you
RjB.
 
i don't want you to do my assignment i just need help when file is read,how each integer will be read and assigned and how to stop after each line .StringTokenizer needs to be used but i don't know how to use it.
 
Take a look at the api for StringTokenizer at
Choose java.util in the upper left pane then StringTokenizer
in the lower right pane
You will want to use the constructor
StringTokenizer
public StringTokenizer(String str,
String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.

Parameters:
str - a string to be parsed.
delim - the delimiters.

Also hint:
You will use a Integer.parseInt(String s) on each of
the returned values. Put that inside a
try->catch(NumberFormatException) block and walk
through the String array.

Try it and if you have problems post the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top