Facebook
From KAMEL MUFTI, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 34
  1. size (600, 600);
  2. // More conditions (Activity 11)
  3.  
  4. int hoffset = 15;
  5. int initialvalue  = 24 ;
  6. String msg;
  7. int cpt = 0;
  8. int value = 0;
  9.  
  10. int cptred = 0;
  11. int cptgreen = 0;
  12. int cptblue = 0;
  13.  
  14. for(int i = 0; i <= initialvalue ; i++){
  15.   cpt++;
  16.   value = i ;
  17.  
  18.   if ((value % 2 ) == 0 && (value % 5 ) == 0  ) { // If the number is even and it is also divisible by 5, then it should be displayed as green.
  19.       fill(0,150,0);
  20.        msg = " " + value ;
  21.       text(msg, 20, cpt * hoffset);
  22.        cptgreen++;
  23.   }
  24.   else if ((value % 2 ) == 0) { //If the number is even, then you should display the number as red.
  25.       fill(255,0,0);
  26.        msg = " " + value ;
  27.       text(msg, 20, cpt * hoffset);
  28.       cptred++;
  29.      
  30.   }
  31.   else {  // If it is any other number, display it as blue.
  32.    fill(0,0,255);
  33.    msg = " " + value ;
  34.    text(msg, 20, cpt * hoffset);
  35.    cptblue++;
  36.   }
  37.  
  38. }
  39.  
  40. cpt++;
  41. msg = "Total even numbers ( red ) ==> " +  cptred;
  42. fill(255,0,0);
  43. text(msg, 20,  (cpt * hoffset)+10);
  44. cpt++;
  45. fill(0,150,0);
  46. msg = "Total even numbers divisible by 5 (green) ==> " +  cptgreen;
  47. text(msg, 20, (cpt * hoffset)+10);
  48. cpt++;
  49.  fill(0,0,255);
  50. msg = "Total other numbers (blue) ==> " +  cptblue;
  51. text(msg, 20,  (cpt * hoffset)+10);
  52.