[CSC 204] Files For Lab
Andrew J. Pounds
pounds_aj at mercer.edu
Wed Feb 11 21:38:27 EST 2009
I have attached three files that you will need for lab on Thursday. To
save time, you might want to set them up in Eclipse before you come to lab.
--
Andrew J. Pounds, Ph.D. (pounds at theochem.mercer.edu)
Associate Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
-------------- next part --------------
import java.util.Scanner;
/**
*
* CSC 204 Factorial program
* Lab 5
* This program will compute the factorial of a value given by the
* user on the command line. It is constrained to use values that
* fit into a primitive integer type.
*
* Recall, n! = 1 * 2 * 3 * ... * n
*
* Keep entering values as long as you wish. Enter 0 to stop.
*
*@author Laurie White
*@version int data type
*/
public class Factorial {
public static void main(String[] args) {
int value; // The value being computed
Scanner in = new Scanner (System.in); // To allow for input
// Get the first value
System.out.print("A value, please (use 0 to stop): ");
value = in.nextInt();
while (value != 0) {
int result = fact(value);
System.out.println(value + "! = " + result);
System.out.print("A value, please (use 0 to stop): ");
value = in.nextInt();
}
}
private static int fact(int n) {
int product = 1;
for (int i = 2; i <= n; i++) {
product *= i;
}
return product;
}
}
-------------- next part --------------
import java.lang.*;
/**
* A program to print the limits of the primitive types
*
* @author Laurie White
* @version byte only
*
*/
public class NumberLimits {
public static void main(String[] args) {
System.out.println("The smallest byte is " + Byte.MIN_VALUE
+ " and the largest byte is " + Byte.MAX_VALUE);
}
}
-------------- next part --------------
import java.lang.Math.*;
public class RoundingOff
{
public static void main (String [] args)
{
System.out.println ("round (3.4) = "+ Math.round (3.4));
}
}
More information about the csc204
mailing list