Computer Science, asked by myidentity, 1 year ago

Tenth ICSE Java program
Please answer the question below :)

Attachments:

Answers

Answered by lastbenchstudent
0

public class Marks{

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) {

Scanner in = Scanner( System.in);

System.out.println("Tell me how many marks ?");

int n = in.nextInt();

int[] marks = new int[n];

System.out.println("Enter Marks");

for(int i=0; i< n ; i++){

marks[i] = in.nextInt();

}

System.out.println();

bubbleSort(marks);//sorting marks using bubble sort

System.out.println("Marks After Bubble Sort");

for(int i=0; i < marks.length; i++){

System.out.print(marks[i]+ " ");

}

}

}

Output:

Similar questions