Мне нужна быстрая помощь в java
Two days, I try to solve this accessory. I can solve it. I hope someone can help me as soon as possible
The problem is I don’t know how to create a file in which the positive numbers are and the other is in the negative
Exercise 2 : Create a file “input.txt” containing an arbitrary integer values (use Math.random) Create 2 files “positive.txt” and “negative.txt” containing respectively positive integers and negative integer from input.txt. Exercise 3 : Exercise 2 using binary files.
Что я уже пробовал:
This is the code I made, but the above things remain
import java.io.*; import java.util.Scanner; public class JavaApplication57 { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { // TODO code application logic here Scanner cc = new Scanner(System.in); System.out.println("Enter the Name of File 1 = \n"); String name1 = cc.nextLine(); System.out.println("Enter the Name of File 2 = \n"); String name2 = cc.nextLine(); ObjectOutputStream O1 = new ObjectOutputStream(new FileOutputStream(name2)); ObjectInputStream I1 = new ObjectInputStream(new FileInputStream(name2)); ObjectOutputStream O2 = new ObjectOutputStream(new FileOutputStream(name1)); ObjectInputStream I2 = new ObjectInputStream(new FileInputStream(name1)); int doubleNu; for(int i =0; i<100;i++){ double k=-1; double m =(double)i; int s=((int)((Math.random()*100)*Math.pow(k, m))); } O1.close(); O2.close(); try { while((doubleNu=I1.readInt())!=1) { O2.writeInt(doubleNu*2); } } catch(EOFException e){ } O2.close(); I1.close(); //ObjectInputStream I2 = new ObjectInputStream(new FileInputStream(name1)); try { while((doubleNu=I1.readInt())!=-1) { System.out.println(" " + doubleNu); } } catch(EOFException e){ } I1.close(); try { while((doubleNu=I2.readInt())!=-1) { System.out.println(" " + doubleNu); } } catch(EOFException e){ } I2.close(); } }
ZurdoDev
Самое важное, что нужно знать разработчику, - это как отлаживать.