Guest User

Untitled

a guest
Apr 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. *
  4. * @author jordanpeck
  5. */
  6. public class SMALLESTfour {
  7.  
  8.  
  9.  
  10. public static void main(String[] args)
  11. {
  12. Scanner kybd = new Scanner(System.in);
  13. System.out.println("Enter 4 Integers: ");
  14. int num1 = kybd.nextInt(); //user enter first number
  15. int num2 = kybd.nextInt(); //user enter second number
  16. int firstsmaller = num1; //the new 'firstsmaller' value is now num1
  17. int secondsmaller = num2; //the new value of second smaller is now num2
  18. int getsmall1 = (smaller(firstsmaller,secondsmaller));//run numbers through method smaller() returning smallest value
  19.  
  20. int num3 = kybd.nextInt(); //user enter number 3
  21. int num4 = kybd.nextInt(); //user enter number 4
  22.  
  23. firstsmaller = num3; //the new 'firstsmaller' value is now num3
  24. secondsmaller = num4; //the new value of second smaller is now num4
  25.  
  26. int getsmall2 = (smaller(firstsmaller,secondsmaller)); //get smallest from num3 and num4 returned through smaller() method
  27.  
  28. firstsmaller = getsmall1; //firstsmaller is now the smallest from the first section (num1 num2)
  29. secondsmaller = getsmall2; //secondsmaller is now smallest from the second section (num3 num4) run through method again
  30.  
  31. System.out.println("Smallest Number is: " + smaller(firstsmaller, secondsmaller)); //output final values of first/secondsmaller
  32.  
  33. }
  34.  
  35. public static int smaller (int firstsmaller, int secondsmaller) //gets the smallest of firstsmaller and second smaller
  36. //everytime they're passed to it
  37. {
  38. int smallest = 0; //set smallest to 0
  39.  
  40. if
  41. (firstsmaller < secondsmaller) //if firstsmaller is less than secondsmaller, return firstsmaller as the smallest value
  42. smallest = firstsmaller; //if secondsmaller is less than firstsmaller, return secondsmaller as the smallest value
  43. else
  44. smallest = secondsmaller; //else vice versa
  45.  
  46. return smallest; //return this value, which has become the value of either firstsmaller or secondsmaller, whichever was smallest
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
Add Comment
Please, Sign In to add comment