Advertisement
Sylv3rWolf

Untitled

Sep 2nd, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. public class zad2 {
  2.     public static int min(int a,int b){
  3.         if (a<b) return a;
  4.         else return b;
  5.     }
  6.     public static Para[] parujTablice(int tab1[], int tab2[], int sum){
  7.         int it = min(tab1.length,tab2.length);
  8.         int rozm = (it+1)/2;
  9.         Para pary[] = new Para[rozm];
  10.         int licznik=0;
  11.         for(int i=0;i<rozm;i+=2)
  12.         {
  13.             pary[licznik] = new Para(tab1[i],tab2[i]);
  14.             if(pary[licznik].suma()==sum)
  15.                 licznik++;
  16.         }  
  17.         return pary;
  18.     }
  19. }
  20. class Para{
  21.     int a,b;
  22.     public int suma(){
  23.         return a+b;
  24.     }
  25.     public Para(int a,int b){
  26.         this.a=a;
  27.         this.b=b;
  28.     }  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement