Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package taskuripetru;
- public class Student {
- private static int[] Student;
- String name;
- int age;
- public Student(String name, int age) {
- this.name = name;
- this.age = age;
- }
- static void bubbleSort(int[] arr) {
- int n = arr.length;
- int temp = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 1; j < (n - i); j++) {
- if (arr[j - 1] < arr[j]) {
- //swap elements
- temp = arr[j - 1];
- arr[j - 1] = arr[j];
- arr[j] = temp;
- }
- }
- }
- }
- public static void main(String[] args) {
- Student st1 = new Student("Victor", 25);
- Student st2 = new Student("Vitalie", 28);
- Student st3 = new Student("Igor", 98);
- Student st4 = new Student("Alexei", 22);
- // st1.name = "Victor";
- // st2.name = "Igor";
- // st3.name = "Vitalie";
- // st4.name = "Alexei";
- // st1.age = 25;
- // st2.age = 28;
- // st3.age = 20;
- // st4.age = 22;
- Student = new int[4];
- int[] Student = {st1.age, st2.age, st3.age, st4.age};
- bubbleSort(Student);
- System.out.println("Studenti sortati dupa virsta in descrestere");
- for (int i = 0; i < Student.length; i++) {
- System.out.print(Student[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement