HarrJ

Day 14 samples

Jul 6th, 2023 (edited)
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. package week2training;
  2.  
  3. public class Day14B {
  4.     public static void main(String[] args) {
  5.         int[] numArray = {10,12};
  6.         int largestNum;
  7.         int smallestNum;
  8.        
  9.         for (int i : numArray) {
  10.             System.out.println(i);
  11.         }
  12.  
  13.         largestNum = Math.max(numArray[0], numArray[1]);
  14.         smallestNum = Math.min(numArray[0], numArray[1]);
  15.        
  16.         System.out.println("Biggest number in array: " + largestNum);
  17.         System.out.println("Smallest number in array: " + smallestNum);
  18.        
  19.     }
  20. }
  21. //---------
  22. package week2training;
  23.  
  24. public class Day14B {
  25.     public static void main(String[] args) {
  26.         int[] numArray = {10,12,15,9,11};
  27.         int largestNum = 0;
  28.         int smallestNum = 0;
  29.        
  30.         for (int i : numArray) {
  31.             System.out.println(i);
  32.             largestNum = Math.max(largestNum, i);
  33.             smallestNum = Math.min(smallestNum, i);
  34.            
  35.             System.out.println("Biggest number in array(current): " + largestNum);
  36.             System.out.println("Smallest number in array(current): " + smallestNum);
  37.         }
  38.        
  39.     }
  40. }
  41.  
  42. //-----------------------------
  43.         System.out.println("Random1: " + Math.round(Math.random() * 10));
  44.         System.out.println("Random2: " + Math.round(Math.random() * 10));
  45.         System.out.println("Random3: " + Math.round(Math.random() * 10));
  46.         System.out.println("Random4: " + Math.round(Math.random() * 10));
  47.         System.out.println("Random5: " + Math.round(Math.random() * 10));
  48.         System.out.println("Random6: " + Math.round(Math.random() * 10));
  49.  
  50. //------draw 6 different number(parang lotto)-----------------------
  51.  
  52. package week2training;
  53.  
  54. public class Day14C {
  55.     public static void main(String[] args) {
  56.         long[] winningNum = {0,0,0,0,0,0};
  57.         int numCount = 0;
  58.         boolean numExist = false;
  59.         long newNumber = 0;
  60.        
  61.         while (numCount < winningNum.length) {
  62.             newNumber = (Math.round(Math.random() * 41) + 1);
  63.             for (long l : winningNum) {
  64.                 if (newNumber == l) {
  65.                     numExist = true;
  66.                     System.out.println("repeat num: " +  newNumber);
  67.                     break;
  68.                 }
  69.             }
  70.             if (numExist == false) {
  71.                 winningNum[numCount] = newNumber;
  72.                 System.out.println("new num: " + newNumber);
  73.                 numCount++;
  74.             } else {
  75.                 numExist = false;
  76.             }
  77.         }
  78.     }
  79. }
  80.  
  81. //-----------------------------
  82.  
  83. String txt2 = "The quick brown fox jumps over the lazy dog";
  84. String txtSearch = "Fox";
  85. boolean findText = txt2.toLowerCase().contains(txtSearch.toLowerCase());
  86. System.out.println("do text below contains the word "+ txtSearch + "?");
  87. System.out.println(txt2);
  88. System.out.println(".contains() " + findText);
  89. System.out.println(".endWith() " + txt2.endsWith("Dog"));
  90.  
  91. double total = 441.28;
  92. double paid = 450;
  93. double change = paid - total;
  94. System.out.println("The amount due is " + total);
  95. System.out.println("You paid " + paid + ". Your change is " + change);
  96. System.out.println("format version:");
  97. System.out.println(String.format("The amount due is %f", total));
  98. System.out.println(String.format("You paid %f. Your change is %f", paid , change));
Advertisement
Add Comment
Please, Sign In to add comment