SHARE
TWEET

câu 3

Khoa98 Feb 15th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top