Advertisement
Guest User

Untitled

a guest
May 30th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Scalanie {
  4.     static int[] tab;
  5.     static int[] tab2;
  6.     static int[] tab3;
  7.     long m;
  8.     public Scalanie(){
  9.         this.m=m;
  10.     }
  11.     public int[] odczyt(String nazwaPliku) throws IOException{
  12.     FileInputStream fis = new FileInputStream(nazwaPliku);
  13.     BufferedInputStream bis = new BufferedInputStream(fis);
  14.     DataInputStream dis = new DataInputStream(bis);
  15.     long m = dis.readLong();
  16.     int[] t = new int[(int)m];
  17.     for(int i=1;i<m;i++){
  18.         t[i]=dis.readInt();
  19.     }
  20.     return t;
  21.     }
  22.     public void scal(int[] tab, int[] tab2){
  23.     int[] t=new int[tab.length+tab2.length];
  24.     for(int i=0;i<t.length;i=i+2){
  25.         t[i]=tab[i];
  26.         t[i+1]=tab2[i];
  27.     }
  28.     }
  29.     public void zapisz(int[] t,String nazwaPliku) throws IOException{
  30.         FileOutputStream fos = new FileOutputStream(nazwaPliku);
  31.         BufferedOutputStream bos = new BufferedOutputStream(fos);
  32.         DataOutputStream dos = new DataOutputStream(bos);
  33.         dos.writeLong(t.length);
  34.         for(int i=1;i<t.length;i++){
  35.             dos.writeInt(t[i]);
  36.         }
  37.     dos.close();
  38.     }
  39.    
  40.     public void wyswietl(int[] a){
  41.             for(int i=0;i<a.length;i++){
  42.                 System.out.print(a[i]+" ");
  43.             }
  44.     }      
  45.     public static void main(String[] args) throws IOException{
  46.         Scalanie s1 = new Scalanie();
  47.         int m=50;
  48.         int[] t1 = new int[m];
  49.         for(int i=0;i<t1.length;i=i+2){
  50.             t1[i]=i;
  51.         }
  52.         int[] t2 = new int[m];
  53.         for(int j=1;j<t2.length;j=j+2){
  54.             t2[j]=j;
  55.         }
  56.         int[] t3 = new int[t1.length+t2.length];
  57.         s1.zapisz(t1,"parzyste");
  58.         s1.zapisz(t2,"nieparzyste");
  59.         tab=s1.odczyt("parzyste");
  60.         tab2=s1.odczyt("nieparzyste");
  61.         s1.wyswietl(tab);
  62.         System.out.println();
  63.         s1.wyswietl(tab2);
  64.         s1.scal(t1, t2);
  65.         s1.zapisz(t3, "liczby");
  66.         tab3=s1.odczyt("liczby");
  67.         System.out.println("Wyniki!");
  68.         s1.wyswietl(tab3);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement