Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. package dmath;
  2.  
  3. /**
  4. *
  5. * @author npark
  6. */
  7. public class Main {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12.  
  13. public static int A[] = new int[6];
  14.  
  15. public static void main(String[] args) {
  16.  
  17. String name = "npark";
  18. int i=0, j=0;
  19. int result=0;
  20.  
  21. A[1]= 3; A[2]=1; A[3]=5; A[4]=2; A[5]=4;
  22.  
  23. result = find_max(A);
  24.  
  25. bubble_sort();
  26.  
  27. //System.out.println("result: "+result);
  28.  
  29. }//main()
  30.  
  31. public static void bubble_sort(){
  32.  
  33. int i=0, j=0, k=1, tmp=0;
  34. System.out.println("");
  35. System.out.println("---------------------------------------------");
  36. System.out.print("Exe/Var");
  37. System.out.print(" i");
  38. System.out.print(" j");
  39. System.out.print(" A[j]");
  40. System.out.print(" A[j+1]");
  41. System.out.println(" T");
  42. System.out.println("---------------------------------------------");
  43.  
  44. System.out.println(" "+k+" "+i+" "+j+" "+A[j]+" "+A[j+1]+" "+tmp);
  45. System.out.println("---------------------------------------------");
  46.  
  47. for(i=1; i<6; i++){
  48.  
  49. k = k + 1;
  50. System.out.println(" "+k+" "+i+" "+j+" "+A[j]+" "+A[j+1]+" "+tmp);
  51. System.out.println("---------------------------------------------");
  52. System.exit(0);
  53.  
  54. for(j=1; j<6-i; j++){
  55. if(A[j] > A[j+1]){
  56. tmp = A[j];
  57. A[j] = A[j+1];
  58. A[j+1] = tmp;
  59. }//fi
  60. }//for(j)
  61. }//for(i)
  62.  
  63. System.out.println("");
  64. //System.out.println("result after sorting");
  65. System.out.println("");
  66.  
  67. for(i=1; i<6; i++){
  68.  
  69. //System.out.println("A["+i+"]: "+A[i]);
  70. }
  71.  
  72. System.out.println("");
  73.  
  74. }// bubble()
  75.  
  76. public static int find_max(int B[]){
  77.  
  78. int max=0;
  79. int i=0;
  80. for(i=0; i<5; i++){
  81. if(max < B[i]){
  82. max = B[i];
  83. }//fi
  84. }//rof
  85.  
  86. return max;
  87.  
  88. }//ftn find_max
  89.  
  90. }//class Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement