fork download
  1. import java.util.*;
  2. public class A4A{
  3. Scanner input=new Scanner(System.in);
  4. String[][] a2 = new String[100][2];
  5. int length;
  6. A4A(){
  7. getValues();
  8. printValues(a2, length);
  9. bubble_srt();
  10. selection_srt();
  11.  
  12. }
  13. public void getValues(){
  14. String line="";
  15. System.out.println("Enter elements of your choice: ");
  16. length=0;
  17. while( length < a2.length && !line.equalsIgnoreCase("done")){
  18. line=input.nextLine();
  19. if (!line.equalsIgnoreCase("done") && !line.isEmpty()){
  20. a2[length][0]=line;
  21. a2[length][1]=line.trim().toLowerCase().substring(0, 1) ;
  22. length++;
  23. }
  24. }
  25.  
  26. }
  27. public void printValues(String[][] p, int size){
  28. for(int i=0; i <size; i++)
  29. System.out.println(i+":"+p[i][1]+":"+p[i][0]);
  30. }
  31. public void bubble_srt(){
  32. int i, j;
  33. String[] temp=new String[2];
  34. String[][] b = a2.clone();
  35.  
  36. for(i = 0; i < length; i++){
  37. for(j = 1; j < (length-i); j++){
  38. if(b[j-1][1].charAt(0) > b[j][1].charAt(0)){
  39. temp = b[j-1];
  40. b[j-1]=b[j];
  41. b[j]=temp;
  42. }
  43. }
  44. }
  45. System.out.println("Bubble Sort");
  46. printValues(b, length);
  47. }
  48. public void selection_srt(){
  49. String [][]s = a2.clone();
  50. for(int x=0; x<length; x++){
  51. int index_of_min = x;
  52. for(int y=x; y<length; y++){
  53. if(s[index_of_min][1].charAt(0) > s[y][1].charAt(0)){
  54. index_of_min = y;
  55. }
  56. }
  57. String[] temp = s[x];
  58. s[x] = s[index_of_min];
  59. s[index_of_min] = temp;
  60. }
  61.  
  62. System.out.println("Selection Sort");
  63. printValues(s, length);
  64. }
  65.  
  66.  
  67. public static void main(String[] args) {
  68. new A4A();
  69.  
  70. }
  71. }
  72.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: class A4A is public, should be declared in a file named A4A.java
public class A4A{
       ^
1 error
stdout
Standard output is empty