Methods #99 (Nice and short)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name:Fill In Functions
/// File Name:FillInFunctions.java
/// Date Finished: 4/4/2016
public class FillInFunctions
{
public static void main( String[] args )
{
System.out.println("Watch as we demonstrate functions.");
System.out.println();
System.out.println("I'm going to get a random character from A-Z");
System.out.println("The character is: " + randomChar() );
System.out.println();
System.out.println("Now let's count from -10 to 10");
int start, stop;
start = -10;
stop = 10;
counter(start, stop);
System.out.println("How was that?");
System.out.println();
System.out.println("Now we take the absolute value of a number.");
int x;
x = -10;
System.out.println("|" + x + "| = " + absolute(x) );
System.out.println();
System.out.println("That's all. This program has been brought to you by:");
credits();
}
public static void credits()
{
System.out.println();
System.out.println("programmed by Joshua Davis");
System.out.println("modified by Amir Salehi");
System.out.print("This code is distributed under the terms of the standard ");
System.out.println("BSD license. Do with it as you wish.");
}
public static char randomChar()
{
int numvalue;
char charvalue;
numvalue = (int)(Math.random()*26);
charvalue = (char) ('A' + numvalue);
return charvalue;
}
public static void counter( int start, int stop )
{
while ( start <= stop )
{
System.out.print( start + " " );
start = start + 1;
}
}
public static int absolute( int x )
{
int abvalue;
if ( x < 0 )
abvalue = -x;
else
abvalue = x;
return abvalue;
}
}
Picture(s) of the output