हिंदी

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.

Advertisements

प्रश्न

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.

संक्षेप में उत्तर
Advertisements

उत्तर

import java.util.Scanner;
class Descending {
public static void main(String args[ ]) {
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print(“Enter number of words you want to enter:”);
n = s.nextlnt( );
String names[ ] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println(“Enter all words:”);
for(int i = 0; i < n; i+ +) {
names[i] = s1.nextLine[( );
}
for (int i = 0; i < n; i+ +){
for (int j = i + 1; j < n;j++){
if (names[i].compareTo(namesG]) < 0) {
temp = names [i];
names[i] = namesG];
names[j] = temp;
}
}
}
System.out.print(“Words in Descending Order:”);
for (int i = 0;i<n-l;i++){
System.out.print(names[i] + “,”);
}
System.out.print(names[n – 1]);
}
}

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2016-2017 (March) Set 1
Advertisements
Share
Notifications



      Forgot password?
Use app×