Advertisement
victorniculin

VN

May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package taskuripetru;
  2.  
  3. public class Student {
  4.  
  5.     private static int[] Student;
  6.  
  7.     String name;
  8.     int age;
  9.  
  10.     public Student(String name, int age) {
  11.         this.name = name;
  12.         this.age = age;
  13.     }
  14.  
  15.     static void bubbleSort(int[] arr) {
  16.         int n = arr.length;
  17.         int temp = 0;
  18.         for (int i = 0; i < n; i++) {
  19.             for (int j = 1; j < (n - i); j++) {
  20.                 if (arr[j - 1] < arr[j]) {
  21.                     //swap elements  
  22.                     temp = arr[j - 1];
  23.                     arr[j - 1] = arr[j];
  24.                     arr[j] = temp;
  25.                 }
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static void main(String[] args) {
  31.  
  32.         Student st1 = new Student("Victor", 25);
  33.         Student st2 = new Student("Vitalie", 28);
  34.         Student st3 = new Student("Igor", 98);
  35.         Student st4 = new Student("Alexei", 22);
  36. //        st1.name = "Victor";
  37. //        st2.name = "Igor";
  38. //        st3.name = "Vitalie";
  39. //        st4.name = "Alexei";
  40. //        st1.age = 25;
  41. //        st2.age = 28;
  42. //        st3.age = 20;
  43. //        st4.age = 22;
  44.         Student = new int[4];
  45.         int[] Student = {st1.age, st2.age, st3.age, st4.age};
  46.         bubbleSort(Student);
  47.         System.out.println("Studenti sortati dupa virsta in descrestere");
  48.         for (int i = 0; i < Student.length; i++) {
  49.             System.out.print(Student[i] + "  ");
  50.         }
  51.  
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement