Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class targilMiun
- {
- public static double[] getInfo()
- {
- Scanner in = new Scanner(System.in);
- double[] a = new double[40];
- int count = 0;
- double h = in.nextDouble();
- while(h!=-1)
- {
- a[count] = h;
- count++;
- h = in.nextDouble();
- }
- double[] b = new double[count];
- for(int i=0;i<count;i++)
- b[i]=a[i];
- return b;
- }
- public static void sort(double[] array)
- {
- double temp;
- int pMin;
- for(int i=0;i<array.length; i++)
- {
- pMin = i;
- for(int j=i+1;j<array.length;j++)
- {
- if(array[j]<array[pMin])
- pMin = j;
- }
- temp = array[i];
- array[i] = array[pMin];
- array[pMin] = temp;
- }
- }
- public static void whereHighest(double[] a, double[] b)
- {
- if(a[a.length-1]>b[b.length-1])
- System.out.println("הגבוה ביותר הוא בכיתה הראשונה");
- else if(a[a.length-1]<b[b.length-1])
- System.out.println("הגבוה ביותר הוא בכיתה השנייה");
- else
- System.out.println("הכי גבוהים בכל כיתה הם באותו גובה");
- }
- public static double avg(double[] a)
- {
- double sum=0.0;
- for(int i=0;i<a.length;i++)
- sum+=a[i];
- return sum/a.length;
- }
- public static double[] Mizug(double[] a, double[] b)
- {
- int p1=0,p2=0,p3=0;
- double[] c = new double[a.length+b.length];
- while(p1<a.length && p2<b.length)
- {
- if(a[p1]<b[p2])
- {
- c[p3] = a[p1];
- p1++;
- }
- else if(a[p1]>b[p2])
- {
- c[p3] = b[p2];
- p2++;
- }
- else
- {
- c[p3] = a[p1];
- p3++;
- c[p3] = b[p2];
- p1++;
- p2++;
- }
- p3++;
- }
- while(p1<a.length)
- {
- c[p3] = a[p1];
- p1++;
- p3++;
- }
- while(p2<b.length)
- {
- c[p3] = b[p2];
- p2++;
- p3++;
- }
- return c;
- }
- public static boolean checkIfTwoMeters(double[] a)
- {
- boolean flag = false;
- for(int i=0;i<a.length;i++)
- if(a[i] == 2)
- flag = true;
- return flag;
- }
- public static void main(String[] args)
- {
- double[] class1 = getInfo();
- sort(class1);
- for(int i=0;i<class1.length;i++)
- System.out.println(class1[i]+" ");
- double[] class2 = getInfo();
- sort(class2);
- for(int i=0;i<class2.length;i++)
- System.out.println(class2[i]+" ");
- whereHighest(class1,class2);
- if(avg(class1)<avg(class2))
- System.out.println("כיתה 1");
- else if(avg(class1)>avg(class2))
- System.out.println("כיתה 2");
- else
- System.out.println("ממוצע שתי הכיתות זהה");
- double[] classTogether = Mizug(class1,class2);
- for(int i=0;i<classTogether.length;i++)
- System.out.println(classTogether[i]+" ");
- if(checkIfTwoMeters(class1) == true)
- System.out.println("יש תלמיד בגובה 2 מטר בכיתה1");
- if(checkIfTwoMeters(class2) == true)
- System.out.println("יש תלמיד בגובה 2 מטר בכיתה2");
- }
- }
Add Comment
Please, Sign In to add comment