Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. import java.util.*;
  2. public class targilMiun
  3. {
  4.     public static double[] getInfo()
  5.     {
  6.         Scanner in = new Scanner(System.in);
  7.         double[] a = new double[40];
  8.         int count = 0;
  9.         double h = in.nextDouble();
  10.         while(h!=-1)
  11.         {
  12.             a[count] = h;
  13.             count++;
  14.             h = in.nextDouble();
  15.         }
  16.         double[] b = new double[count];
  17.         for(int i=0;i<count;i++)
  18.             b[i]=a[i];
  19.         return b;
  20.        
  21.     }
  22.     public static void sort(double[] array)
  23.     {
  24.         double temp;
  25.         int pMin;
  26.         for(int i=0;i<array.length; i++)
  27.         {
  28.             pMin = i;
  29.             for(int j=i+1;j<array.length;j++)
  30.             {
  31.                 if(array[j]<array[pMin])
  32.                     pMin = j;
  33.             }
  34.             temp = array[i];
  35.             array[i] = array[pMin];
  36.             array[pMin] = temp;
  37.         }
  38.     }
  39.     public static void whereHighest(double[] a, double[] b)
  40.     {
  41.         if(a[a.length-1]>b[b.length-1])
  42.             System.out.println("הגבוה ביותר הוא בכיתה הראשונה");
  43.         else if(a[a.length-1]<b[b.length-1])
  44.             System.out.println("הגבוה ביותר הוא בכיתה השנייה");
  45.         else
  46.             System.out.println("הכי גבוהים בכל כיתה הם באותו גובה");
  47.     }
  48.     public static double avg(double[] a)
  49.     {
  50.         double sum=0.0;
  51.         for(int i=0;i<a.length;i++)
  52.             sum+=a[i];
  53.         return sum/a.length;
  54.     }
  55.     public static double[] Mizug(double[] a, double[] b)
  56.     {
  57.         int p1=0,p2=0,p3=0;
  58.         double[] c = new double[a.length+b.length];
  59.         while(p1<a.length && p2<b.length)
  60.         {
  61.             if(a[p1]<b[p2])
  62.             {
  63.                 c[p3] = a[p1];
  64.                 p1++;
  65.             }
  66.             else if(a[p1]>b[p2])
  67.             {
  68.                 c[p3] = b[p2];
  69.                 p2++;
  70.             }
  71.             else
  72.             {
  73.                 c[p3] = a[p1];
  74.                 p3++;
  75.                 c[p3] = b[p2];
  76.                 p1++;
  77.                 p2++;
  78.             }  
  79.             p3++;
  80.         }
  81.         while(p1<a.length)
  82.         {
  83.             c[p3] = a[p1];
  84.             p1++;
  85.             p3++;
  86.         }
  87.         while(p2<b.length)
  88.         {
  89.             c[p3] = b[p2];
  90.             p2++;
  91.             p3++;
  92.         }
  93.         return c;
  94.        
  95.     }
  96.     public static boolean checkIfTwoMeters(double[] a)
  97.     {
  98.         boolean flag = false;
  99.         for(int i=0;i<a.length;i++)
  100.             if(a[i] == 2)
  101.                 flag = true;
  102.         return flag;
  103.     }
  104.     public static void main(String[] args)
  105.     {
  106.         double[] class1 = getInfo();
  107.         sort(class1);
  108.         for(int i=0;i<class1.length;i++)
  109.             System.out.println(class1[i]+" ");
  110.        
  111.         double[] class2 = getInfo();
  112.         sort(class2);
  113.         for(int i=0;i<class2.length;i++)
  114.             System.out.println(class2[i]+" ");
  115.        
  116.         whereHighest(class1,class2);
  117.         if(avg(class1)<avg(class2))
  118.             System.out.println("כיתה 1");
  119.         else if(avg(class1)>avg(class2))
  120.             System.out.println("כיתה 2");
  121.         else
  122.             System.out.println("ממוצע שתי הכיתות זהה");
  123.        
  124.         double[] classTogether = Mizug(class1,class2);
  125.         for(int i=0;i<classTogether.length;i++)
  126.             System.out.println(classTogether[i]+" ");
  127.        
  128.         if(checkIfTwoMeters(class1) == true)
  129.             System.out.println("יש תלמיד בגובה 2 מטר בכיתה1");
  130.         if(checkIfTwoMeters(class2) == true)
  131.             System.out.println("יש תלמיד בגובה 2 מטר בכיתה2");
  132.     }
  133.  
  134. }
Add Comment
Please, Sign In to add comment