Advertisement
JavaCoffeeBean

FillInFunction

Nov 15th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. // Fill-In Functions - Fix the broken functions and function calls.
  2.  
  3. public class FillInFunctions
  4. {
  5. public static void main( String[] args )
  6. {
  7. // Fill in the function calls where appropriate.
  8.  
  9. System.out.println("Watch as we demonstrate functions.");
  10.  
  11. System.out.println();
  12. System.out.println("I'm going to get a random character from A-Z");
  13. char c = '!';
  14. System.out.println("The character is: " + randchar() + c );
  15.  
  16. System.out.println();
  17. System.out.println("Now let's count from -10 to 10");
  18. int begin, end;
  19. begin = -10;
  20. end = 10;
  21. counter(begin, end);
  22. System.out.println("How was that?");
  23.  
  24. System.out.println();
  25. System.out.println("Now we take the absolute value of a number.");
  26. int x, y = 99;
  27. x = -10;
  28. abso();
  29. System.out.println("|" + x + "| = " + y );
  30.  
  31. System.out.println();
  32. System.out.println("That's all. This program has been brought to you by:");
  33. credits();
  34. }
  35.  
  36. public static void credits()
  37. // No parameters.
  38. {
  39. // displays some boilerplate text saying who wrote this program, etc.
  40.  
  41. System.out.println();
  42. System.out.println("programmed by Graham Mitchell");
  43. System.out.println("modified by Stuart Roper");
  44. System.out.print("This code is distributed under the terms of the standard ");
  45. System.out.println("BSD license. Do with it as you wish.");
  46.  
  47. //return credits;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. public static char randchar()
  54. // No parameters.
  55. {
  56. // chooses a random character in the range "A" to "Z"
  57.  
  58. int numval;
  59. char charval;
  60.  
  61. // pick a random number from 0 to 25
  62. numval = (int)(Math.random()*26);
  63. // now add that offset to the value of the letter 'A'
  64. charval = (char) ('A' + numval);
  65.  
  66. return charval;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. public static int counter(int start, int stop )
  73. // Parameters are:
  74. // int start;
  75. // int stop;
  76. {
  77. // counts from start to stop by ones
  78. int ctr;
  79.  
  80. ctr = start;
  81. while ( ctr <= stop )
  82. {
  83. System.out.print(ctr + " ");
  84. ctr = ctr+1;
  85. }
  86.  
  87. return ctr;
  88. }
  89.  
  90.  
  91.  
  92. public static int abso( int value )
  93. // Parameters are:
  94. // int value;
  95. {
  96. // finds the absolute value of the parameter
  97. int absval;
  98.  
  99. if ( value < 0 )
  100. absval = -value;
  101. else
  102. absval = value;
  103.  
  104. return absval;
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement