Advertisement
Blonk

Untitled

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