Advertisements
Advertisements
प्रश्न
Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order. Display the sorted array and original array.
Advertisements
उत्तर
import java.util.*;
public class Charsort {
public static void bubbleSort(char[] array) {
int num = array.length;
char temp = 0;
for (int i = 0; i < num; i++) {
for (int j = 1; j < (num - i);j++) {
if (array[j - 1] > array[j]) {
temp = array[j - 1];
array[j - 1] = array[j];
array[j] = temp;
}
}
}
}
public static void main(String[] args) {
char array[] = new char[10];
Scanner sc=new Scanner(System.in);
System.out.println(;'Enter 10 characters:");
for(int i=0;i<10;i++)
array[i]=sc.nextLine().charAt(0);
System.out.println("Array Before Bubble Sort:
" + Arrays.toString(array));
bubbleSort(array);
System.out.println("Array After Bubble Sort:"
+ Arrays.toString(array));
}
}APPEARS IN
संबंधित प्रश्न
What is the difference between the linear search and the binary search technique?
Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.
Design a class to overload a function series() as follows:
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ……………. xn terms
(b) void series (int p) – To display the following series:
0, 7, 26, 63 p terms.
(c) void series () – To display the sum of the series given below:
`1/2 + 1/3 + 1/4 .....1/10`
Name the following :
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
Differentiate between searching and sorting.
If int x [ ] = { 4, 3,7, 8, 9,10}; what are the values of p and q ?
(i) p = x.length
(ii) q = x[2] + x[5] * x[1]
Write a program to input forty words in an array. Arrange these words in descending order of alphabets, using selection sort technique. Print the sorted array.
Write a program to accept a name and total marks of N number of students in two single subscript array name[] and totalmarks[].
Calculate and print:
- The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N] - Deviation of each student’s total marks with the average
[deviation = total marks of a student – average]
Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a = new int (5);
for (int i = 0; i < = 5; i++) a [i] = i;
Consider the given array and answer the question given below:
int x[ ] {4; 7,9,66,72,0,16);
What is the value in x[4]?
