السلام عليكم ورحمة الله وبركاته
سوري اخواني بس انا محاوله يعني احله بس نسيت احطي المحاوله يعني حليت بارت منه و حاولت احل الباقي بس ما عرفت يعني حاولت
السؤال يعني المطلوب:
محاولتي بس ما عرفت كيف اكمل الباقي:اقتباسUse DataInputStream and DataOutputStream classes, to read from the keyboard a set of integers, store them in a file. Then open the same file again for reading and calculate the number of lines, sum, and find the maximum number. Follow the steps bellow:1. Create the method writeData(OutputStream out), to:
a. Create DataOutputStream object to be associated with out.
b. Read integer data from keyboard
c. Write data to out
d. Repeat steps b and c till end of file is read.
e. Close the DataOutputStream.
2. Create the method readData(InputStream in), to
a. Create DataInputStream object to be associated with in.
b. Read integer data from in.
c. Calculate the sum, max, and number of lines in the file
d. Repeat steps b and c till end of file is read.
e. Display the result (sum, max and number of lines) in the standard output device.
f. Close the DataInputStream.
3. In the main() method:
a. Create two Streams, one to read from the file "data" and one to write to it.
b. Call the writeData() method first, after that call readData()
c. Close both streams.
import java.io.*;
public class Ass02{
public static void main(String [] args){
try{
DataOutputStream out = new DataOutputStream(new FileOutputStream("data"));
writeData(out);
}catch(IOException ioe){}
}//main
//read byte from keyboard and write integer to file
public static void writeData(OutputStream o) throws IOException{
DataOutputStream oStream = (DataOutputStream) o;
InputStream key = System.in;
int data = key.read();
oStream.writeInt(data);
oStream.close();
}//writedata
}اتمنى تساعدوني