Advertisement
Khoa98

câu 3

Feb 15th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         int B[] = {8, 4, 5, 10, 13, 15, 12};
  6.  
  7.         System.out.println(BaSoLonNhat(B));
  8.     }
  9.  
  10.     public static String BaSoLonNhat(int B[]) {
  11.         int max1 = 0, max2 = 0, max3 = 0;
  12.         int dem = 0;
  13.         int vt = 0, vt1 = 0;
  14.  
  15.         for (int i = 0; dem < 3; i++) {
  16.             if (dem == 0) {
  17.                 if (max1 <= B[i]) {
  18.  
  19.                     max1 = B[i];
  20.                     vt = i;
  21.                 }
  22.             }
  23.             if (dem == 1) {
  24.                 if (max2 <= B[i] && i != vt) {
  25.  
  26.                     max2 = B[i];
  27.                     vt1 = i;
  28.                 }
  29.             }
  30.             if (dem == 2) {
  31.                 if (max3 <= B[i] && i != vt && i != vt1) {
  32.  
  33.                     max3 = B[i];
  34.                 }
  35.             }
  36.             if (i == B.length - 1) {
  37.                 i = 0;
  38.                 dem += 1;
  39.             }
  40.         }
  41.         return max1 + " " + max2 + " " + max3;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement