Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Scalanie {
- static int[] tab;
- static int[] tab2;
- static int[] tab3;
- long m;
- public Scalanie(){
- this.m=m;
- }
- public int[] odczyt(String nazwaPliku) throws IOException{
- FileInputStream fis = new FileInputStream(nazwaPliku);
- BufferedInputStream bis = new BufferedInputStream(fis);
- DataInputStream dis = new DataInputStream(bis);
- long m = dis.readLong();
- int[] t = new int[(int)m];
- for(int i=1;i<m;i++){
- t[i]=dis.readInt();
- }
- return t;
- }
- public void scal(int[] tab, int[] tab2){
- int[] t=new int[tab.length+tab2.length];
- for(int i=0;i<t.length;i=i+2){
- t[i]=tab[i];
- t[i+1]=tab2[i];
- }
- }
- public void zapisz(int[] t,String nazwaPliku) throws IOException{
- FileOutputStream fos = new FileOutputStream(nazwaPliku);
- BufferedOutputStream bos = new BufferedOutputStream(fos);
- DataOutputStream dos = new DataOutputStream(bos);
- dos.writeLong(t.length);
- for(int i=1;i<t.length;i++){
- dos.writeInt(t[i]);
- }
- dos.close();
- }
- public void wyswietl(int[] a){
- for(int i=0;i<a.length;i++){
- System.out.print(a[i]+" ");
- }
- }
- public static void main(String[] args) throws IOException{
- Scalanie s1 = new Scalanie();
- int m=50;
- int[] t1 = new int[m];
- for(int i=0;i<t1.length;i=i+2){
- t1[i]=i;
- }
- int[] t2 = new int[m];
- for(int j=1;j<t2.length;j=j+2){
- t2[j]=j;
- }
- int[] t3 = new int[t1.length+t2.length];
- s1.zapisz(t1,"parzyste");
- s1.zapisz(t2,"nieparzyste");
- tab=s1.odczyt("parzyste");
- tab2=s1.odczyt("nieparzyste");
- s1.wyswietl(tab);
- System.out.println();
- s1.wyswietl(tab2);
- s1.scal(t1, t2);
- s1.zapisz(t3, "liczby");
- tab3=s1.odczyt("liczby");
- System.out.println("Wyniki!");
- s1.wyswietl(tab3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement