fork download
  1. package bublesort;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  *
  7.  * @author NguyenNgocDai
  8.  */
  9. public class BubleSort {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. Scanner st= new Scanner(System.in);
  14. int s=0;
  15. System.out.println("Nhap so phan tu cua mang:");
  16. s= st.nextInt();
  17. // new Scanner(System.in).nextLine();
  18. int[] nums=new int[s];
  19. for(int i=0; i<s; i++){
  20. System.out.println("Nhap phan tu thu "+ (i+1)+" :");
  21. try{
  22. nums[i]=st.nextInt();
  23. // new Scanner(System.in).nextLine();
  24. System.out.println("Error.");
  25. }
  26. }
  27. for(int i=0; i<s-1; ++i){
  28. for(int j=i+1; j<s; ++j){
  29. if(nums[i]>nums[j]){
  30. int t;
  31. t=nums[i]; nums[i]=nums[j]; nums[j]=t;
  32. }
  33. }
  34. }
  35. System.out.println("Sorted Array is:");
  36. for(int i=0; i<s; ++i){
  37. System.out.print(" " + nums[i]);
  38. }
  39. System.out.println("");
  40. }
  41.  
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0.05s 4386816KB
stdin
3
4 
3
1
compilation info
Main.java:9: error: class BubleSort is public, should be declared in a file named BubleSort.java
public class BubleSort {
       ^
1 error
stdout
Standard output is empty